It looks like you want to add a new proxy object so that EF can notice the changes.
As mentioned in StriplingWarrior CreateObject<T> , a proxied version of T is just created, you need to add it (for inserts) or Attach it (for updates) for EF to find out.
Reading between lines in code, it looks like you want to do an insert?
If this is true, a proxy is not even required.
Why?
Well, you do not need to track changes in the level of ownership (i.e., know what properties have been changed), all you need to know is that the object is new and needs to be inserted.
Add a call to ctx.MyEntities.Add(...) tells EF that.
This means that for inserts this is enough:
var entity = new MyEntity(); ...
Or that
var entity = ctx.CreateObject<MyEntity>(); ...
both will work. But the first is easier to understand.
Hope this helps
Alex (Microsoft)
source share