Hi Guys,
This could be a simple solution, but....
If i have a Entity Framework 4 Repository which exposes the following interface:
void InsertOrUpdate(Foo foo);
And my EDM is done with custom POCO's (no code generation), how do i perform UPDATE's to POCO's?
I can INSERT a new object by doing this:
var newFoo = new Foo { ... };
repo.InsertOrUpdate(newFoo);
That works if i implement that method with ObjectContext.AddObject.
But if i try and UPDATE an object:
var existingFoo = repo.Find(foo);
existingFoo.Name = "Changed the foo!";
repo.InsertOrUpdate(existingFoo);
I get an error saying an entity with the same key already exists, which makes sense - but i though the ObjectContext.AddObject method was smart enough to do an INSERT or UPDATE?
How do we handle inserts and updates in EF4 POCO Repos? Do i have to do a query to the DB first to see if it's there, if it isn't then do AddObject, if it is - what do i do?