我想从linq中调用一个存储过程,这个存储过程有5个参数,但我只想传递/需要其中的2个。
当我在代码中添加参数时,由于它需要全部5个参数,所以无法构建。请问应该如何调用这个存储过程?
我想从linq中调用一个存储过程,这个存储过程有5个参数,但我只想传递/需要其中的2个。
当我在代码中添加参数时,由于它需要全部5个参数,所以无法构建。请问应该如何调用这个存储过程?
MyDbDataContext db = new MyDbDataContext();
db.MyStoredProc(customerID, "sometext", null, null, null);
成功与失败将取决于您存储过程中处理这些最后3个参数的SQL语句是否为空。
overload 存储过程调用。
我没有它在我面前,但你需要去你的 DataAccessName.cs 文件并创建一个与相同签名的方法名称
自动生成的存储过程方法签名:
void sp_sproc(int a, int b, int c, int d, int e);
这个在你的DataAccessName.cs文件中完成
void sp_sproc(int a, int b)
{
this.sp_sproc(a,b,0,0,0);
}
void sp_sproc(int? a, int? b, int? c, int? d, int? e);
那么你可以这样做
void sp_sproc(int a, int b)
{
this.sp_sproc(a,b,null,null,null);
}