I get a LINQ object from MVC2 that I want to update to the database. My current code looks like this:
public PersonTbl Save(PersonTbl item)
{
if (item.ID == 0) //new item
{
_dbContext.PersonTbls.InsertOnSubmit(item);
}
else
{
var item2 = _dbContext.PersonTbls.Single(i => i.ID == item.ID);
item2.LastName = item.LastName;
item2.FirstName = item.FirstName;
item2.MobilePhone = item.MobilePhone;
}
_dbContext.SubmitChanges();
return item;
}
What I'm basically wondering is why there is no UpdateOnSubmit(item) function. Is it any way I can solve this another way?