最佳做法-使用存储过程和数据插入数据LINQ [英] Best Practices - Inserting Data using Stored Procedures & LINQ

查看:71
本文介绍了最佳做法-使用存储过程和数据插入数据LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:)

我一直在使用LINQ,并希望获得有关如何使用LINQ插入数据的建议.

我已经阅读了一些有关如何在LINQ中使用insert SPROCS的文章.

我试图在这里介绍基础知识.

我有一个名为Client_Insert的SPROC.现在,我已阅读的文章建议我将Client表(在这种情况下)添加到OR映射器,并指定Insert属性进行Customize,并提及将数据添加到Client表的SPROC.

我只是希望将参数传递给SPROC并使用LINQ执行它.

问题.
1.据我了解,使用OR映射器(如上所述)的唯一原因是限制仅通过SP添加数据.这是正确的吗?

2.我想创建一个辅助函数,该函数在LINQ框架内并使用(DBTransaction)事务执行SP.如果我不使用LINQ,我将传递一个SQLParameters数组
例如
SqlParameter [] Myparam

如何将参数传递给使用LINQ框架执行插入SP的辅助函数?


3.请给我其他有用的建议:)

祝你有美好的一天!

Hi Everyone :)

I have been using LINQ and would like advice on how to use LINQ for inserting data.

I have reviewed some articles on how to use insert SPROCS with LINQ.

I am trying to get down to the basics here.

I have an SPROC called Client_Insert. Now the articles that I have read advice me to add the Client table (in this case) to the OR mapper and specify the Insert property to Customize and mention the SPROC for adding data to the Client table.

I simply wish to pass the parameters to the SPROC and execute it using LINQ.

Questions.
1. As I understand the only reason to use the OR mapper (as mentioned above) is to restrict adding the data through an SP only. Is this correct?

2. I want to create a helper function that executes an SP within the LINQ framework and using a (DBTransaction) transaction. If I were not using LINQ I would be passing an array of SQLParameters
e.g.
SqlParameter[] Myparam

How will I pass parameters to a helper function that executes an insert SP using the LINQ freamework?


3. Please give me any other useful advice :)

Have a great day!!

推荐答案

我不知道这是否回答了你的问题.

在linq中使用存储过程时,请在方括号中传递所需的参数,例如

I don''t know if this answers your question or not.

When using a stored procedure in linq you pass the required parameters in brackets e.g.

string result = fdc.ProcInsertTransactions(Par1,Par2,Par3).ToString();



如果您需要交易,最好的选择是在SQL的proc端进行交易.



if you require a transaction the best option would be to do it on the proc side within SQL.


这篇关于最佳做法-使用存储过程和数据插入数据LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆