开发者

EF code first return subset of columns

I have a table with about 12 columns. But there are time when I only need 2 or 3 columns.

I am using Entity Framework code first to query the database from my website.

What should I do so that I do not query all the columns but only a subset开发者_运维知识库 of columns?

Thanks, Mike


You can use a projection to an anonymous type that contains the properties you want, i.e if your Foo entity has the properties A, B and C you could do:

var results = context.Foos.Select( x => new { x.A, x.B });

to retrieve only the properties A and B.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜