开发者

Limiting fields returned in a LINQ query

开发者 https://www.devze.com 2023-01-28 23:00 出处:网络
A few days ago I asked a question about returning select fields from a LINQ query. Now, I want to add some grouping to the results and things are not working out.

A few days ago I asked a question about returning select fields from a LINQ query. Now, I want to add some grouping to the results and things are not working out.

The following query returns the correct rows but I want to limit the fields returned. For example, I only want to see the Id and Name fields.

var开发者_Python百科 contactsFromDealers = Contacts.Where(x => x.ContactTypeID == 2).GroupBy (x => x.OrganizationName)

and appending .Select (x => x.Id, x.OrganizationName) doesn't help.

Any suggestions? Thanks!


you need the select before the group by i believe.


try .Select( x => new { x.Name } )

0

精彩评论

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