tags:

views:

578

answers:

3

I using linq 2 sql with the asp.net mvc. I am having two table schedular and schdulerhistory and I am having a stored procedure which will insert data in this two table with one transaction.

I want to use that stored procedure with the linq. How i can accomplish this things with linq 2 sql.

A: 

Scott Gu has an article on using stored procedures with LINQ to SQL.

Jon Freeland
this is not the answer. I want to insert into two tables while he is having only one table
jalpesh
It sounds like this is not actually a LINQ question then...? Please clarify.
Jon Freeland
A: 

In your server explorer, drag your stored procedure into your DBML file.

Once this is done, you can create an instance of your DataContext object and call that stored procedure directly as if it were a class level method.

For example:

MyDataContext db = new MyDataContext();

var storedProcedureResultSet = db.NameOfMyStoredProcedure(parameter);

Smeggles
A: 

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

KM
how to use that stored procedure with linq?
jalpesh
see links in answer (just added them)
KM