English 中文(简体)
Entity Framework Code First lazy loading non navigation properties
原标题:

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

问题回答
  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.





相关问题
named connection not found (Entity framework problem)

I m building multi-project Application where some UserControl, the user control has a Entitymodel object (myDBContainer db = new myDBContainer()), when i drop my user control on my a form i got the ...

EF4 POCO - Updating a navigation property

I have a Recommendation object and a FeedbackLevel object and the FeedbackLevel object is a navigation property inside a Recommendation object Recommendation int EntityKey; FeedbackLevel Level; ...

How can I add constraints to an ADO.NET Entity?

I know how to mark a group of fields as primary key in ADO.NET entities but i haven t found a way to declare unique constraints or check constraints. Is this feature missing on the designer or on the ...

Using sql date data type and EF4

I have a table w/ a sql date data type. When I look at the EDM markup, the storage element reflects this. The conceptual entity has a data type of DateTime (there doesn t appear to be a Date data type)...

RIA services, EF and stored procs

I have this problem for 2 months now How can I use stored procedures whith RIA. I was using LinqToSql and everithing works fine. I ve made an class in designer and mapped it to a SP. Now in EF I ...

Mocking Entity Context in EF4

I am using VS2010 B2 and EF4 B2 and trying to use Rhino Mocks to mock the entity context generated by EEF. var context = MockRepository.GenerateMock<SomeDBEntities>(); IObjectSet<TxMode> ...

热门标签