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

2
  • 1
    Just a guess. There is a Table Splitting approach, maybe it will help: thedatafarm.com/blog/data-access/… Commented Nov 1, 2010 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. Commented Nov 5, 2010 at 12:18

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.