views:

44

answers:

2

Hi!

I 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?

+1  A: 

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.

Ladislav Mrnka
+1 for the idea, but did you test this way and it works? You sure the model will allow multiple types for the same table? Also, how will I map between the two types (i.e. TableFull, TableSummary)?
Shimmy
Ok, my bad. I was sure that this should be possible but quick test shown me that EF team again let me down. Mapping two unrelated entities to the same table look like big problem. It started with error that entities share primary key and solving this issue with some hack only raised other issues.
Ladislav Mrnka
I think Entity Framework is a great idea, it's just a pity that it's managed by Microsoft's lazy teams. Cuz so many key-features are missing. Is there any products better than EF (with a designer)?
Shimmy
I added some other idea.
Ladislav Mrnka
+1  A: 

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.

Nuno Ramiro
Yes I tried. but it's impossible to map views in EF!Read another question I posted before posting this one (I actually posted this one after being frustrated of that one): http://stackoverflow.com/questions/3581034/create-one-to-one-relationship-between-table-and-view-in-ef4
Shimmy