Last post Jun 18, 2015 12:35 PM by maggiemays
Jun 17, 2015 12:52 PM|maggiemays|LINK
I have several tables that need to be either inserted when new or updated. I want to put these updates/inserts inside a try-catch so that if there's a problem, I won't do anything.
How does that work with entity framework? I'm also going to need to use the key on my first table insert as foreign keys in the other tables. I see there's a command, "SaveChanges". Is it possible to use one SaveChanges or do I need to do this for
each table ?
Jun 17, 2015 05:08 PM|Mikesdotnetting|LINK
You can combine several operations in one transaction: https://msdn.microsoft.com/en-gb/data/dn456843.aspx#several
Jun 18, 2015 06:25 AM|Zhi Lv - MSFT|LINK
I'm also going to need to use the key on my first table insert as foreign keys in the other tables. I see there's a command, "SaveChanges". Is it possible to use one SaveChanges or do I need to do this for each table ?
As for this issue, if you are using transaction, I suppose could use one savechange method.
From your description, it seems you want to update One-to-Many or Many-To-Many Entity using DBContext. If that is the case, you could refer to the following links:
Jun 18, 2015 12:35 PM|maggiemays|LINK