在 Nhibernate 中为命名参数赋值的问题
我对 Nhibernate 比较陌生。我正在尝试更新存储过程。 我在命名查询中得到了以下部分。
<sql-query name="TestUpdate">
exec UpdateTest :DateField :StringField :IntField :BoolField :NullIntField
</sql-query>
Testupdate 是一个存储过程,其中有一个简单的更新语句。我正在使用以下代码行更新参数。
int? testdata = null;
IQuery query = Session.GetNamedQuery("TestUpdate");
query.SetDateTime("DateField", DateTime.Now.AddDays(10));
query.SetString("StringField", "UK");
query.SetInt32("IntField", 100);
query.SetBoolean("BoolField", true);
if(testdata.HasValue)
query.SetInt32("NullIntField", testdata.GetValueOrDefault());
else
{
query.SetParameter("NullIntField", null,NHibernateUtil.Int32);
}
var cmd = new SqlCommand(query.QueryString, (SqlConnection)Session.Connection);
cmd.ExecuteNonQuery();
但是,当我查看 query.QueryString
的值时,它仍然指向相同的值(exec UpdateTest :DateField :StringField :IntField :BoolField :NullIntField
)。似乎命名参数没有被分配。我应该怎么做才能解决这个问题?
我正在使用 SharpArchitecutre,它使用流畅的 nhibernate 来查询数据。
请注意,我已经在论坛中搜索了这个特定问题,但找不到示例。
我确信这个问题可能是微不足道的,但到目前为止我找不到解决方案。
任何帮助表示赞赏。
I am relatively new to Nhibernate. I am trying to update a stored procedure.
I got the below section in the named query.
<sql-query name="TestUpdate">
exec UpdateTest :DateField :StringField :IntField :BoolField :NullIntField
</sql-query>
Testupdate is a stored procedure which will has a simple update statement in it. I am updating the parameters using the following line of code.
int? testdata = null;
IQuery query = Session.GetNamedQuery("TestUpdate");
query.SetDateTime("DateField", DateTime.Now.AddDays(10));
query.SetString("StringField", "UK");
query.SetInt32("IntField", 100);
query.SetBoolean("BoolField", true);
if(testdata.HasValue)
query.SetInt32("NullIntField", testdata.GetValueOrDefault());
else
{
query.SetParameter("NullIntField", null,NHibernateUtil.Int32);
}
var cmd = new SqlCommand(query.QueryString, (SqlConnection)Session.Connection);
cmd.ExecuteNonQuery();
However, when I look at the value of query.QueryString
, it still points to the same value (exec UpdateTest :DateField :StringField :IntField :BoolField :NullIntField
). It seems like the named parameters are not getting assigned. What should I do to get around this problem?
I am using SharpArchitecutre, which uses fluent nhibernate to query the data.
Please note, I have searched the forum for this particular issue and I couldn't land on an example.
I am sure the issue could be trivial, but I couldn't find a solution so far.
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NHibernate 中对存储过程的支持很少。有关更多信息,请查看 NH 文档: http://nhibernate .info/doc/nh/en/index.html#querysql-limits-storedprocedures
也许这可能对您有所帮助:http://ayende.com/blog/1692/using-nhibernate-with-stored -程序
There is little support for stored procedures in NHibernate. For more information, check out the NH documentation: http://nhibernate.info/doc/nh/en/index.html#querysql-limits-storedprocedures
And perhaps this might help you along: http://ayende.com/blog/1692/using-nhibernate-with-stored-procedures