If the form displays data from just one model, saving is easy using Table.InsertOnSubmit(entity) then SubmitChanges. However, what if you have to save data to more than on related tables? Is there an easy way to do this? Does my question make sense?
The SubmitChanges collects all the changes you have specified and executes SQL to commit them to the database.
If you haven't set any TransactionScope then the changes are wrapped in a new transaction (so a failure of any one of the inserts will cause none of the inserts to happen)
MDeibert
Member
20 Points
72 Posts
Is there an easy way to save to multiple related tables?
Jun 18, 2008 08:28 PM|LINK
If the form displays data from just one model, saving is easy using Table.InsertOnSubmit(entity) then SubmitChanges. However, what if you have to save data to more than on related tables? Is there an easy way to do this? Does my question make sense?
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: Is there an easy way to save to multiple related tables?
Jun 18, 2008 10:40 PM|LINK
This lies firmly outside the scope of MVC. it depends completely on your BLL/DAL.
So what are you using for your back end? Entity Framework? Linq to Sql classes? SubSonic? your own custom thing?
Either way, you should ask the question on the appropriate forum.
Thanks
Paul Linton
Star
13403 Points
2531 Posts
Re: Is there an easy way to save to multiple related tables?
Jun 19, 2008 02:18 AM|LINK
You can have multiple InsertOnSubmit calls like this
The SubmitChanges collects all the changes you have specified and executes SQL to commit them to the database.
If you haven't set any TransactionScope then the changes are wrapped in a new transaction (so a failure of any one of the inserts will cause none of the inserts to happen)