开发者

how to select a subset of fields in a linq to azure storage query

I have

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

I only want some of the columns from the table. Doing

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

Doesnt work: e开发者_StackOverflow中文版mits the field names as part of the REST query ($select=ID,Model) and azure returns 'InvalidInput'


It should work starting from version 2011-08-18, see Writing LINQ Queries Against the Table Service.

The following example projects 3 properties from an entity that has 10 properties. In this example, SampleEntity’s 10 properties are letters from A through 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
                                  };


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

Select - not supported - All properties of an entity are retrieved on any read operation. Projection is not supported.

So you simply can't do this projection at the table interface level - you have to select all the fields

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜