views:

42

answers:

2

Hi,

need some help or some advice with entity framework v4. As you already know, EF v4 does not support lazy loading of scalar properties. If i have some entity object for example Order in model with many scalar properties, some of them expensive to load from DB, like attached file for example. As i found later, it is possible to move these expensive properties to another entity for example Order1 and remap them to DB table. So original DB table will be mapped to 2 entities - Order - with properties ID and Name and Order1 - with all others. What i need to do? In User Interface i will have a ListBox filled with entity Order (ID - Name of all orders) on left side and all other expensive properties of Order1 on rigt side for clicked order in listbox. Properties from Order1 lazy loaded, and with working savechanges, delete objects etc ... . How to make business object for order as entities are separated and how to setup with wpf binding ... . Need just some kick the right way ... :/

thanks

A: 

Having 2 models complicates your program, and can be a source of bugs. I would rather use a single model and then selectivily load items as I needed them.

I meant use only one entity framework model. Looks like you are doing this already. What you need to do in to explicitly load data when you need it, see http://msdn.microsoft.com/en-us/library/bb896249.aspx.

This is actually a design desision from MS, to force you to be aware of which data you need at which times. With automatic lazy loading it works, but then you can get into problems later due to scaling issues.

Shiraz Bhaiji
you mean 2 entities for same DB table? or 2 entity framework models? I have only 1 entity framework model. How selectively load items? when i have only one entity for Order DB table, i can load 2 collumns like this var query = db.Order.Select(o => new { IDorder = o.IDorder, Name = o.Name }) .ToList().Select(x => new Order{IDorder = x.IDorder, Name = x.Name}); but with such query savechanges is not working because of context ... .
vikox
A: 

you mean 2 entities for same DB table? or 2 entity framework models? I have only 1 entity framework model. How selectively load items? when i have only one entity for Order DB table, i can load 2 collumns like this

           var query = db.Order.Select(o => new { IDorder = o.IDorder, Name = o.Name })
                        .ToList().Select(x => new Order{IDorder = x.IDorder, Name = x.Name});

but with such query savechanges is not working because of context ... .

vikox
sorry, tried to comment your answer Shiraz, but i couldn`t :/
vikox