How to insert data into two tables from linq 2 sql with stored procedure

I am using linq 2 sql with asp.net mvc. I have two table graphs and a schdulerhistory and I have a stored procedure that will insert data into these two tables with one transaction.

I want to use this stored procedure with linq. How can I accomplish this using linq 2 sql.

-1


a source to share


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:



http://www.mssqltips.com/tip.asp?tip=1542

http://www.google.com/search?hl=en&as_q=linq+to+sql%2C+how+to+call+a+stored+procedure&as_epq=&as_oq=&as_eq=&num=100&lr=&as_filetype=&ft=i&as_sitesearch= & as_qdr = all & as_rights = & as_occt = any & cr = & as_nlo = & as_nhi = & safe = images

0


a source


Scott Gu has an article on Using Stored Procedures with LINQ to SQL.



0


a source


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







All Articles