Usually I have an integer identity primary key I can detect if an object needs to be inserted by doing
public partial class MyObject
{
public void Save(DataContext context)
{
if (this.PrimaryKey == 0) context.MyObjects.InsertOnSubmit(this);
context.SubmitChanges();
}
}
But in the case I'm working on the primary key is a string and is populated by code. Is there any way to create a similar save method that inserts the object automatically if necessary? Thanks.