开发者

Linq-to-Sql execute custom stored procedure for update records

I little confused about updating data with a stored procedure in linq 2 sql. My question is: when I use stored procedure to update some data in data base (but this stored procedure doesn't mapped to some particular entity) is I shoul invoke SubmitChanges after it. And also what about transaction when I invoke a number of such procedures in loop, should I explicit create transaction through Connection.BeginTransaction() method or model do it for me?

Again, I k开发者_运维问答now how it works when stored procedure linked with some entity in model, but now I wont to use custom stored procedure that update records in a number of tables.

Appreciate your help!


Updating non-entity data via stored procedure and LINQ to SQL is very straightforward. Just drag the stored procedure from Server Explorer onto empty space in the DBML designer (so it won't try to return entity objects) and call the associated generated method in your code like this:

myDataContext.MyStoredProcedureMethod();

The action is performed immediately, so you don't need to call SubmitChanges().

To wrap this call (or loop, or whatever) in a LINQ to SQL transaction, see the instructions and examples here for how to use LINQ to SQL transactions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜