I'm using a loose coupling between presentation and my domain entites. When the client calls SubmitChanges it correctly calls my insert method on the server, passing up the "to-be-added" presentation model instance.
The server side code will does the insert including generating a primary key. But how am I to pass this primary key back to the client?
Update: In response to comment let me give more detail: Yes, I'm using RIA Service, but the entities that the RIA Services service exchanges with the client are not the same as the entities that go to the database. Therefore I can't rest on some behind the scenes magic at the server side. My insert method signature looks like so:
public void InsertPerson(PersonInfo source)
{
}
The PersonInfo class looks like this:
public class PersonInfo
{
[Key]
public Guid Id { get; set; }
public String Name { get; set; }
// you get the point
}
During the process of inserting the primary key is determined (server side) The client side obviously needs this information, how does it get it?
@GarethOwen Even with POCO objects the id values as long as they are set to the POCO object within the service they should be updated on the client. Normally though you don't set the POCO ID if you aren't using a Guid. So if you are using an int for an ID then you can do it this way.
public void InsertPOCO(POCOObj POCO)
{
RealObj x = new RealObj();
x.Info = ...(information)...;
this.DataContext.RealObjs.InsertOnSubmit(RealObj);
this.DataContext.SubmitChanges();
// Once the Submit Changes has run, the x object will then have an id value associated with it, and you can now assign the ID value of the POCO Object
POCO.Id = x.Id;
}
And then you don't have to re-query the domain service for the Id value.