Stop EF From Loading Entities When Assigning Association

Using Entity framework v4, and the POCO entity generator T4 templates.

The problem I have is that the Fixup methods are loading hundreds of entities when I assign an associated entity (see line 4 below).

Dim context = New SomeEntities
Dim list = context.Lists.FirstOrDefault(Function(l) l.ListId = 2)
Dim queryDetail = context.CreateObject(Of QueryDetail)()
queryDetail.CriteriaColumnType = context.CriteriaColumnTypes.FirstOrDefault(Function(cct) cct.CriteriaColumnTypeId = 145)

The CriteriaColumnType entity that is being assigned has a collection of QueryDetail objects, and when the assignment is made, the FixUp method on the CriteriaColumnType entity is lazy loading all of the associated QueryDetails.

How can I create the FK association and attach the CriteriaColumnType entity to my QueryDetail entity without loading all of the CriteriaColumnType's QueryDetail records?

6
задан Steve Horn 7 September 2010 в 18:51
поделиться