3

Is there a simple solution to make lazy load for nonnavigation property in the EF 4.1? For example, for byte array.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
zonder
  • 253
  • 5
  • 12

2 Answers2

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).

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • @zonder, +1, totally agree with you. That "Table-splitting" strategy is the ugliest workaround for absense of such a necessary feature as regular ordinary lazy-loading. – Vasiliy R Apr 27 '11 at 21:10
  • EF s*cks. I have a table with an xml payload that I would like to be able to exclude some (actually most) of the time. Do you think I can - no. I have decided to just load it for now, and I am going back to creating connections manually. I always end up tossing these frameworks after a short while. Time and time again. – Jim Mar 08 '12 at 07:35
-1

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.

w.brian
  • 16,296
  • 14
  • 69
  • 118
  • For example, when you need to use entity for displaying in a list and for creating or updating. You don't need to load all the infroration of entity in case of a list. That's one of a lot situation when you need to use just part of entity data. – zonder Jul 20 '11 at 16:01
  • Anything bigger than a simple string, like image data, xml or other such payload data that is attached to an entity. Why should I have to create a one-to-one relationship and indexes every time I have an image / xml or whatever. One to one relationships are a pain at the best of times, so why proliferate them. – Jim Mar 08 '12 at 07:38