2011-07-18 47 views
0

選擇字段的一個子集我有如何在LINQ到Azure存儲查詢

var query = 
     from Dev device 
     in storage.QueryEntities<Dev>("dev") 
     where device.PartitionKey == "1" 
     select device; 

我只想要一些從表中的列。這樣做

var query = 
     from Dev device 
     in storage.QueryEntities<Dev>("dev") 
     where device.PartitionKey == "1" 
     select new {device.ID, device.Model}; 

does not工作:發出的字段名稱爲REST查詢的一部分($選擇= ID,型號)和天藍色的回報 'InvalidInput'

回答

1

http://msdn.microsoft.com/en-us/library/dd135725.aspx

選擇 - 不支持 - 在任何讀取操作中檢索實體的所有屬性。投影不受支持。

所以,你根本無法在表界面級別中投影 - 你必須選擇所有字段

+0

你總是可以做局部投影...所以是這樣的:VAR的東西=(從開發設備......選擇設備) .ToList()。選擇(d => new {d.ID,d.Model};或類似的東西。 – smarx

1

它應該從2011-08-18版本開始,請參閱Writing LINQ Queries Against the Table Service

以下示例從具有10個屬性的實體中投影3個屬性。在這個例子中,SampleEntity的10個屬性是從A字母到J:

IEnumerable<SampleEntity> query = from entity in 
            dataServiceContext.CreateQuery<SampleEntity>(tableName) 
            where entity.PartitionKey == "MyPartitionKey" 
            select new SampleEntity 
            { 
             PartitionKey = entity.PartitionKey, 
             RowKey = entity.RowKey, 
             A = entity.A, 
             D = entity.D, 
             I = entity.I 
            };