How to insert data into two tables from linq 2 sql with stored procedure
3 answers
One stored procedure with two inserts:
CREATE PROCEDURE YouProcedureName
(
@Params1 char(2)
,@Params2 int
,@Params3 varchar(10)
)
AS
INSERT INTO YourTable1
(Col1 , Col2)
VALUES
(@Parms1 , @Params2)
INSERT INTO YourTable2
(Col1 , Col3)
VALUES
(@Parms1 , @Params3)
GO
how to call a stored procedure from LINQ:
0
a source to share
In your server explorer, drag and drop your Stored Procedure into your DBML file.
Once this is done, you can instantiate your DataContext object and call this stored procedure directly as if it were a class level method.
For instance:
MyDataContext db = new MyDataContext ();
var storedProcedureResultSet = db.NameOfMyStoredProcedure (parameter);
0
a source to share