存储过程的数据加载选项 [英] Data Load options with Stored procs
问题描述
您好,
在Linq中调用存储过程到Sql时,使用dataLoadOptions立即加载是否明智?我自己也看不到任何好处,因为它不是我打电话的linq查询。我很感激您对
的建议。
Would it be wise to use immediate loading with dataLoadOptions when calling stored procs in Linq to Sql? I cannot really see any benefit myself because it is not a linq query I am calling. I would appreciate your advise on this.
谢谢
推荐答案
Hello N.Afache ,
欢迎来到MSDN论坛,感谢您在此发帖。
我认为将linq中的存储过程调用到sql很方便。让我们看一个使用
NorthWind 数据库的示例。
I think it is convenient to call stored procs in linq to sql. Let's see an example using NorthWind database.
< span style ="font-family:" Segoe UI"" sans-serif" ;; color:black; font-size:10pt">首先,我们创建一个名为Customers Count By Region的存储过程,如下所示:
ALTER PROCEDURE [dbo]。[NonRowest]
( @ param1 NVARCHAR(15))
AS
< span style ="font-family:" Verdana","sans-s erif英寸;颜色:黑色; font-size:8pt"> BEGIN
SET NOCOUNT ON;
DECLAER @count int
SELECT @count = COUNT(*)FROM Customers
WHERECustomers.Region = @ Param1
RETURN @count
END
我们需要做的就是在O / R Designer中拖动存储的proc,自动生成以下代码:
[功能(名称=“ dbo。[客户按地区计算]”)]
Public int Customers_Count_By_Region([Parameter
(DbType =“ NVarChar(15)”)] string param1)
{
IExecuteResult result = this.ExecutemethodCall(this,
IExecuteResult result = this.ExecutemethodCall(this,
((MethodInfo)(MethodInfo.GetCurrentMethod())),param1);
return((int)(result.ReturnValue));
}
我们可以随时调用它。例如:
Int count = db.CustomersCountByRegion(&ndquo; WA”);
Console.WriteLine(count);
那就是它。所以如果你想了解更多关于实体框架中的存储过程,请阅读这篇文章:
http://www.ef-faq.org/sprocs-and-functions.html
如果您有任何疑问,请告诉我们。
祝你有个愉快的一天,
这篇关于存储过程的数据加载选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!