Actually I just installed .net 4.0, so I want to use linq in my application. I know how to create store procedure, but how ti use linq to create store procedure( for all 3 purpose insert, update, delete). let me know please.
Thanks
Gaurav
It is our choices that show what we truly are, far more than our abilities...
ALTER PROCEDURE dbo.Insert_Leave
(
@User_Id nvarchar(50),
@Dept_To nvarchar(50),
@Leave_Type nvarchar(50),
@Total_Leave_HR int,
@Leave_From datetime,
@Leave_To datetime,
@Leave_Half_Full nvarchar(50),
@Comments nvarchar(1000),
@Leave_Status nvarchar(10)
)
AS
begin
insert into mtbl_Leave_Data(User_Id, Dept_To, Leave_Type, Total_Leave_HR, Leave_From, Leave_To, Leave_Half_Full, Comments, Leave_Status ) values (@User_Id, @Dept_To, @Leave_Type, @Total_Leave_HR, @Leave_From, @Leave_To, @Leave_Half_Full, @Comments, @Leave_Status )
end
now here 2 classes I have regading this Leave.dbml LeaveDataContext and my table mtbl_Leave_Data and also have a form where I have controls like textbox calendar etc.
This is I done through your link. But later this tutorial goes out of my mind as I am new to do this. so could you please
tell me through some coding how can I insert data, I am not saying put full code but just an example.
before this I used to insert data using command object like
sqlcommand com =new sqlcommand("sp" ,connection)
com.parameters.add(...........).value = textbox1.text
com.executenonquery();
Could you please
Thanks
It is our choices that show what we truly are, far more than our abilities...
From serverexplorer drop your stored procedure into rigt side window of Leave.dbml page
In Leave.dbml page right click on the mtbl_Leave_Data(Your Table) ->configurebehaviour
class(choose your table name)
Behaviour(choose Insert)
Click on the customize(Choose your stored Procedure)
and set the method arguments and class properties
after that in your code file
Leave ctx1 = new Leave ();
mtbl_Leave_Data d = new mtbl_Leave_Data();
d.User_Id ="";
.
.
.
ctx1.mtbl_Leave_Data.InsertOnSubmit(d);
ctx1.SubmitChanges();
sorry i just do a writing mistake.
And actually it is a power of linq by which stored procedure automatically call,as yo configure behaviour of table for insert operation by the
method that i told you in the starting
it is a power of linq by which stored procedure automatically call,when you configure behaviour of table for insert operation
by the method that i told you in the starting, after that every time when you insert by the linq method then automatically stored procedure is
called,(you can see this by tracing the sql server )
it is a power of linq by which stored procedure automatically call,when you configure behaviour of table for insert operation by the method that i told you in the starting, after that every time when you insert by the linq method then automatically stored procedure
is called,(you can see this by tracing the sql server )
but how it would know which sp need to call and which not as we did not mention the sp name...?
It is our choices that show what we truly are, far more than our abilities...
demoninside9
Participant
1258 Points
1720 Posts
store procedure with linq
Feb 22, 2012 03:40 AM|LINK
Hi all,
Actually I just installed .net 4.0, so I want to use linq in my application. I know how to create store procedure, but how ti use linq to create store procedure( for all 3 purpose insert, update, delete). let me know please.
Thanks
Gaurav
vish02chouha...
Member
303 Points
251 Posts
Re: store procedure with linq
Feb 22, 2012 03:59 AM|LINK
Use this link For stored procedure with linq
http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx
http://weblogs.asp.net/scottgu/archive/2007/08/23/linq-to-sql-part-7-updating-our-database-using-stored-procedures.aspx
demoninside9
Participant
1258 Points
1720 Posts
Re: store procedure with linq
Feb 22, 2012 08:53 AM|LINK
Thanks vish,
I have created class file named Leave.dbml.
http://s13.postimage.org/7jzk96tlj/leave.jpg
and also created a sp
ALTER PROCEDURE dbo.Insert_Leave ( @User_Id nvarchar(50), @Dept_To nvarchar(50), @Leave_Type nvarchar(50), @Total_Leave_HR int, @Leave_From datetime, @Leave_To datetime, @Leave_Half_Full nvarchar(50), @Comments nvarchar(1000), @Leave_Status nvarchar(10) ) AS begin insert into mtbl_Leave_Data(User_Id, Dept_To, Leave_Type, Total_Leave_HR, Leave_From, Leave_To, Leave_Half_Full, Comments, Leave_Status ) values (@User_Id, @Dept_To, @Leave_Type, @Total_Leave_HR, @Leave_From, @Leave_To, @Leave_Half_Full, @Comments, @Leave_Status ) end now here 2 classes I have regading this Leave.dbml LeaveDataContext and my table mtbl_Leave_Data and also have a form where I have controls like textbox calendar etc. This is I done through your link. But later this tutorial goes out of my mind as I am new to do this. so could you please tell me through some coding how can I insert data, I am not saying put full code but just an example. before this I used to insert data using command object like sqlcommand com =new sqlcommand("sp" ,connection) com.parameters.add(...........).value = textbox1.text com.executenonquery(); Could you please Thanksvish02chouha...
Member
303 Points
251 Posts
Re: store procedure with linq
Feb 22, 2012 11:09 AM|LINK
From serverexplorer drop your stored procedure into rigt side window of Leave.dbml page
In Leave.dbml page right click on the mtbl_Leave_Data(Your Table) ->configurebehaviour
class(choose your table name)
Behaviour(choose Insert)
Click on the customize(Choose your stored Procedure)
and set the method arguments and class properties
after that in your code file
demoninside9
Participant
1258 Points
1720 Posts
Re: store procedure with linq
Feb 23, 2012 02:23 AM|LINK
what is "s" in this code ( s.InsertOnSubmit(d)) and where did you use store procedure ..?
vish02chouha...
Member
303 Points
251 Posts
Re: store procedure with linq
Feb 23, 2012 03:51 AM|LINK
See above, my updated answer
demoninside9
Participant
1258 Points
1720 Posts
Re: store procedure with linq
Feb 23, 2012 04:25 AM|LINK
thanks for correcting , but where is sp...?
vish02chouha...
Member
303 Points
251 Posts
Re: store procedure with linq
Feb 23, 2012 04:36 AM|LINK
vish02chouha...
Member
303 Points
251 Posts
Re: store procedure with linq
Feb 23, 2012 04:37 AM|LINK
''''''
demoninside9
Participant
1258 Points
1720 Posts
Re: store procedure with linq
Feb 23, 2012 06:17 AM|LINK
but how it would know which sp need to call and which not as we did not mention the sp name...?