Is there a simple solution to make lazy load for nonnavigation property in the EF 4.1? For example, for byte array.
问题:
回答1:
No EF doesn't provide lazy loading for scalar and complex properties. The trick is to use table splitting where data from single table are mapped into two entities related with one-to-one relation. One entity is the principal and it contains navigation property to the dependent and because of that you can use lazy loading. Here is the question with link how to do it in EDMX and the answer provides solution for mapping in code-first (comments contains link to another example in MSDN forum).
回答2:
I can't think of any situation where you'd desire a lazy loaded column in a table and couldn't justify putting it in its own table and mapping a separate entity to represent it. If you want a column lazy loaded, its probably a good indication that you need to create a separate entity. If you are mapping EF to a legacy database, then ignore everything I just said.