I see a lot of people asking a similar question, but not this exact one. I'm trying to do what I would hope would be relatively simple with POCO proxies.
using (var context = new MyObjectContext())
{
context.ContextOptions.ProxyCreationEnabled = true;
// this does indeed create an instance of a proxy for me...
// something like Product_SomeBunchOfNumbersForProxy
var newEntity = context.CreateObject<MyEntity>();
// throws exception because newEntity is not in ObjectStateManager...why??
context.ObjectStateManager.GetObjectStateEntry(newEntity);
// ok, well I guess let's add it to the context manually...
context.AddObject("Model.Products", newEntity);
// doesn't throw an exception...I guess that's good
var state = context.ObjectStateManager.GetObjectStateEntry(newEntity);
// prints System.Data.EntityState.Unchanged...oh...well that's not good
Console.WriteLine(state.State);
// let's try this...
context.DetectChanges();
// doesn't throw an exception...I guess that's good
state = context.ObjectStateManager.GetObjectStateEntry(newEntity);
// prints System.Data.EntityState.Unchanged...still no good...
Console.WriteLine(state.State);
// dunno, worth a shot...
context.Refresh(RefreshMode.ClientWins);
// throws exception because newEntity is not in ObjectStateManager...
// that didn't help...
state = context.ObjectStateManager.GetObjectStateEntry(newEntity);
}
What am I doing wrong? Thanks!