I am trying to do an update in Linq.
public myFunc(MyItem newItem)
{
using(var db = new myDataContext())
{
var item = (from o in db.myTable where o.id == myId select o).First();
item = newItem;
db.SubmitAllChanges();
}
}
This doesn't update the object, I guess item = newItem changes item to refer to the other. If I change the individual fields (item.Name = newItem.Name etc.) te change is reflected, however I don't want to spread the contents of the MyItem class into multiple places to reduce maintainability. Is there some way to make the item=newItem copy on a field by field basis?
Also MyItem has a relationship to another table, and I want to update the subordinate items from newItem into item too. (FWIW, there are no adds or deletes, just updates.) Is there a standardized process for doing this?
Thanks for you help.