开发者

Entity Framework: Exclude columns from the selection in Entity Framework?

I开发者_StackOverflow中文版 want to have an ObjectQuery that returns tracked entities (not static data), but I don't want it to load all the columns, I want some columns to load as null, I don't want to use select, since this will return an IEnumerable of the values, not tracked objects.

Is there a way to do it?

If yes, how do I then complete reloading those columns on demand?


Have you tried creating a view and then mapping the view?

By creating a view you can select the columns that you really want and only those will show up on the Entity Model.


I think the only way is to create new entity type which will not contain columns you don't need. You will map this entity type to the same table. On demand (lazy) loading works only for navigation properties.

Edit:

My previous idea doesn't work but in some special cases you can use idea from this article. Instead of modeling single entity from single table you will model multiple entities related with 1:1 relations. Entities will not overlap in properties (except the primary key) as my previous idea assumed because it doesn't work. You will than have main entity with fields you want to load immediately and related entities which will be lazy loaded when needed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜