c# - How can I Insert/Update into two related tables in one command? -
A database exists with two tables < / P>
- Data_t: 1. Apart from this, another field is 'LEFT' TINYINT
- Data_Link_t: DataID PK and FK where DataId exists in data_t. Apart from this, another field 'Right' Smallling
Coming from the Microsoft Access Environment to C # and SQL Server I am looking for a good method to import a record in this relationship. .
is included in the record, which is included in both sides of this conjunction (possibly up to 5000 records to be put up / update at a time) in any type of LINQ list type order the whole batch is processed Bonus to do, but even if it is recorded by record, the main goal is that both parties of this record should be processed in one step.
Countless approaches and I am seeing a lot of people how should I go so that I thought faster to ask ordinary people. Is LINQ the option to add / update a large list of LINQ to SQL? Should I record by record? What approach should I use to add a record to the tables that are recorded in normal, when combined, then make a complete record?
Looks like there is a case where I write a small stored procedure and say to C # - eg, as a function on my Linq-to-SQL data reference object
Something like this:
Get started as CREATE PROCEDURE dbo.InsertData (@Left TINYINT, @Right SMALLINT) DEBLARE @DATADATE INT IN DIBO.DATTY (left) ) Values (@left) Selection @ DataData = SCOPE_IDENTITY (); If you import your data into context, you can call it like this:
Using(YourDataContext ctx = new YourDataContext) {foreach (YourObjectType obj in yourListOfObjects) {ctx.InsertData (obj.Left, obj.Right)}}
and Let the stored proof handle everything else (all the details, such as identifying and using the first table on the second number) for you.