I have a MVC3 Project and I have run into a problem. I have a Create controller which takes as a parameter one of my POCO objects. I add this object to the database like this:
entity = dbSet.Add(entity);
After this method returns, I would like to use the lazy loading features of the object. Unfortunately the object is not a Proxy object generated by the EntityFramework...Is there a way to somehow solve this?
Thank You, AFrieze
The entity must be already proxied when you pass it to
Add
method.Add
method will not return another instance of the class and you cannot change the type of the existing instance to the proxy type.Your options are:
dbSet.Create
- this will create empty proxied detached entity.dbSet.Create
and copy data from received one to created onedbSet.Create
instead of default entity constructor.