I have an object model that’s mapped to a database table. The update query looks like this for now:
public MyObjectModel CreateNewRecord(MyObjectModel TheNewObject)
{
using (MyDataContext TheDC = new MyDataContext())
{
TheDC.MyTable.InsertOnSubmit(TheNewObject);
}
return TheNewObject;
}
That code is not working for the insert part (it tells me that InsertOnSubmit has some invalid arguments). In addition, I’d like to return the inserted object so that I can get the value of the primary key of the inserted item.
What do I need to change?
Thanks for your help.
If
MyTableis of typeTable<ObjectModel>, you can only add objects of typeObjectModel. Try to create yourMyObjectModelclass with all of its properties in the linq2sql designer.