【发布时间】:2010-02-11 17:53:46
【问题描述】:
使用 Subsonic 3.0.0.3 是否可以将空值传递给存储过程参数?如果可以,合适的方式是什么?
详情
假设我有一个 sp,其中一个参数具有默认值,例如:
CREATE Procedure Test_SPWithNullParams( @p1 int=null, @p2 varchar(50) )
AS
SELECT 1 as Stuff
然后在我的代码中我想要执行以下操作:
var db = new Sandbox.DB();
StoredProcedure sproc = db.Test_SPWithNullParams( null , "test");
//alternately --> db.Test_SPWithNullParams("test");
对应函数在StoredProcedures.cs中生成的方式,但是@p1的参数不能为空。那么我的替代方案是什么?我遇到了这篇文章 (http://brianmrush.wordpress.com/2010/01/19/subsonic-t4-templates-stored-procedures-nullable-parameters),但它似乎是一项繁琐的工作,有效地分支了代码库。
另外,我考虑过手动覆盖命令对象。类似的东西:
int dummyInt = -1;
StoredProcedure sproc = db.Test_SPWithNullParams( dummyInt , "test");
sproc.Command.Parameters[0].ParameterValue = DBNull.Value;
想法?
【问题讨论】:
标签: sql-server stored-procedures subsonic subsonic3