13

I'm using the entity framework code first CTP4.

Is it possible to lazy load non navigation properties like you can in NH 3.

A common example would be having a table containing a binary column. I only want to retrieve this column's data when I explicitly ask for that property in my code e.g. image.ImageData

Thanks Ben

Ben Foster
  • 34,340
  • 40
  • 176
  • 285
  • 1
    Just a guess. There is a Table Splitting approach, maybe it will help: http://thedatafarm.com/blog/data-access/ef-table-splitting-ndash-the-opposite-of-entity-splitting/ – Devart Nov 01 '10 at 12:42
  • Yes this is what we used to do with NH before support for lazy loaded properties was added. Looks like the same will be true of EF code first. – Ben Foster Nov 05 '10 at 12:18

1 Answers1

2
  1. Vote here
  2. Vote here
  3. Read this
  4. Ugly workaround:

    public static void Main()
    {
      IEnumerable<MyTable> table;
      using (Entities context = new Entities())
      {
        var buffer =
          context.MyTable
          .Select(myTable => new
          {
            Id = myTable.Id,
            OtherColumn = myTable.OtherColumn
          })
          .ToArray();
    
        table = buffer
          .Select(t => new MyTable 
          {
            Id = t.Id, 
            OtherColumn = t.OtherColumn
          });
      }
    }
    

This will not select the rest of the fields.

Community
  • 1
  • 1
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632