none
ADO.NET EF6: loading a subset of the contents of a Navigation Property include previous loading subset. How to remove previous subset? RRS feed

  • Question

  • our application uses Entity Framework 6.

    In the Book "Programming Entity Framework DbContext" by Julia Lerman and Rowan Miller on page 42

    context.Entry(canyon).Collection(d=>d.Lodgings).Query().Where(l=>l.Contains("Hotel").Load()

    Julia mentions "It is important to remember that calling Load will not clear any objects are already in the navigation property.

    So if you loaded Lodgings at the Grand Canyon that contain the word 'Hotel' and then also loaded Lodgings that contain the word "Campsite", the Lodgings navigation property will contain both hotels and campsites."

    Our application includes configRun and each configRun include several detailRunInfo and detailRunInfo is collection of navigation property of configRun.

    ConfigRun1 may include 3 detailRunInfo and ConfigRun2 may include 2 detailRunInfo.

    We use Eager Loading by using "Include".

    After loading ConfigRun1 with its 3 detailRunInfo, we try to loading ConfigRun2 with its 2 detailRunInfo, we notice that we actually get 5 detailRunInfo (include both from ConfigRun1 and ConfigRun2).

    configRun = Context.ConfiguredRuns.Include(c => c.DetailRunInfos).SingleOrDefault(c => c.ConfiguredRunID = configID);

    Is there a way that we can remove or filter previous loading subset of detailRunInfo for ConfigRun1? Thx!


    JaneC

    Friday, December 5, 2014 4:32 PM

Answers