Question

I am working with the EntityFramework 4.3.1 in Visual Studio 2010.

I have a root entity object called container which has a navigation property called containerversions hanging off of it.

When a new containerversion is required I:

  1. New up a containerversion object
  2. Get the root container through the EF context
  3. Add the new containerversion to the containerversions list property.
  4. Save the context via Context.SaveChanges()

All of which works fine.

However, after the save when I look at the container object and inspect the containerversions collection property, the new containerversion is there, but it's navigation properties are not populated and it's type is not a System.Data.Entity.DynamicProxy but the newed up type of the object I created to add to the collection before saving.

Is there something I am missing when I am saving the rootentity that will cause the newly inserted containerversion navigation properties to be populated?

Was it helpful?

Solution

If you created the entity just by calling new ContenerVersion you will never get dynamic proxy for that instance. To get dynamic proxy you must use objectContext.CreateObject or dbContext.ContainerVersions.Create

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top