2013-05-27 2 views
0

저는 이것에 익숙하지 않습니다. 나는 기존의 푸른 색 테이블 저장소에 연결하는 MVC 4 응용 프로그램을 구축 중입니다. 지금은 필자가 일부 쿼리를 수행하고 그 결과를 응용 프로그램 페이지 중 하나에 표시해야한다는 것을 의미하는 "필터"를 만들어야합니다. 는 지금은 다음과 같습니다뷰에 쿼리 결과를 보내는 방법 (MVC 4 & Azure 테이블 스토리지)

모델 :

public class psEntity : TableEntity 
    { 
     public psEntity() { } 
     public string Message { get; set; } 
     public string RoleName { get; set; } 
     public string BatchName { get; set; } 
     public string DeploymentID { get; set; } 
     public string Description { get; set; } 
    } 

보기

@model IEnumerable<MvcApplication6.Models.psEntity> 

@{ 
    ViewBag.Title = "Performance Status"; 
} 

<h2>Performance Status</h2> 

<p> 
    @Html.ActionLink("Create New", "Create") 
</p> 
<table> 
    <tr> 
     <th> 
      @Html.DisplayNameFor(model => model.Message) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.RoleName) 
     </th> 
     <th></th> 
    </tr> 

@foreach (var item in Model) { 
    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.Message) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.RoleName) 
     </td> 

    </tr> 
} 

컨트롤러 :

public class MailingListController : Controller 
    { 
     public MailingListController() 
     { 
      CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
      ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString); 
     } 

     public ActionResult Index() 
     { 
      TableQuery<psEntity> query=new TableQuery<psEntity>().Where(
       TableQuery.GenerateFilterCondition("RoleName", 
       QueryComparisons.Equal,"Contacts.Worker.Azure")); 
    foreach (psEntity list in query) 
       { 
        lists.Add(list); 
       } 
       return View(lists); 

     } 

내 질문에 순서대로 쿼리 다음에 오는 것입니다 보기에서 만든 테이블의 특정 데이터 만 표시합니다. 내가 foreach 문을 사용하여 시도했지만 오류가 발생했습니다

, 그렇지 않기 때문에

"foreach 문 유형 Microsoft.WindowsAzure.Storage.Table.TableQuery> MVCApplication6.Models.psEntity> 의 변수에 작동 할 수 없습니다 'GetEnumerator' "에 대한 공용 정의를 포함합니다.

Retrieve all entitiesHow to: Retrieve all entities in a partition

은, 파티션에있는 모든 개체에 대한 테이블을 쿼리 TableQuery 객체를 사용하려면 :

사전에

답변

0

확인이 감사합니다. 다음 코드 예제는 'Smith'가 파티션 키인 엔터티에 대한 필터를 지정합니다. 이 예는 조회 결과의 각 엔티티 필드를 콘솔에 인쇄합니다.

// Retrieve the storage account from the connection string. 
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString")); 

// Create the table client. 
CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); 

// Create the CloudTable object that represents the "people" table. 
CloudTable table = tableClient.GetTableReference("people"); 

// Construct the query operation for all customer entities where PartitionKey="Smith". 
TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Smith")); 

// Print the fields for each customer. 
foreach (CustomerEntity entity in table.ExecuteQuery(query)) 
{ 
    Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey, 
     entity.Email, entity.PhoneNumber); 
} 
+0

그냥 내가 foreach 끝을 사용하여 이미 언급 한 오류가 언급 한 시도했다. –

+0

실행중인 코드는 무엇입니까? –

관련 문제