开发者

load partial entityset ef4

开发者 https://www.devze.com 2023-02-16 18:36 出处:网络
Can I load only a few properties from an Entity? As an example I have an entity with the following properties:

Can I load only a few properties from an Entity?

As an example I have an entity with the following properties:

ID
DESCRIPTION
HEADER
PICTURE

I o开发者_JAVA技巧nly want to load the IDs and not the other properties.

How can I do this?


In your case if you just need the IDs, you can use the following query:

var ids = context.YourEntities.Select(e => e.ID).ToList();

You can also use projection (useful if you need to load more than one property):

var entitiesWithIdsAndHeaders = context.
                                YourEntities.
                                Select(e => new
                                            {
                                                Id = e.ID,
                                                Description = e.Description
                                            }).
                                ToList();
0

精彩评论

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