如何在nhibernate中使用存储过程
你好 我尝试在nhibernate中使用存储过程,我发现了一些方法:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<sql-query name="CO_Visites_Treeview_Sel">
exec CO_Visites_Treeview_Sel :Idclient, :Idmagasin, :Autre, :Tous
</sql-query>
</hibernate-mapping>
如果我想使用我将使用的数据:
var query = session.GetNamedQuery("CO_Visites_Treeview_Sel");
query.SetString("Idclient", lstClients.SelectedValue.ToString());
query.SetInt32("Idmagasin", 36);
query.SetBoolean("Autre", false);
query.SetBoolean("Tous", true);
var results = query.List();
在这种情况下,我不会有智能,结果['colName']
我使用另一种方法:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernate.DataAccess.Models.Visites_Treeview,NHibernate.DataAccess" lazy="true">
<id name="Idvisite" column="IDVISITE" type="string">
<generator class="assigned" />
</id>
<property column="NOMMAGASIN" name="Nommagasin" type="string" />
<property column="DATEVIS" name="Datevis" type="DateTime" />
<property column="INTERVENTION" name="Intervention" type="Boolean" />
<property column="IDFACTURE" name="Idfacture" type="string" />
<property column="STATUT" name="Statut" type="byte" />
<property column="NOFACTURE" name="Nofacture" type="int" />
<property column="NODEVIS" name="Nodevis" type="int" />
<property column="LIVRE" name="Livre" type="Boolean" />
<property column="NOCOMMANDE" name="Nocommande" type="int" />
<property column="COMPTABILISEE" name="Comptabilisee" type="Boolean" />
<property column="RECUP" name="Recup" type="Boolean" />
<property column="MASQUE" name="Masque" type="Boolean" />
</class>
<sql-query name="CO_Visites_Treeview_Sel">
<return alias="Visites_Treeview" class="NHibernate.DataAccess.Models.Visites_Treeview,NHibernate.DataAccess">
<return-property column="NOMMAGASIN" name="Nommagasin" />
<return-property column="IDVISITE" name="Idvisite" />
<return-property column="DATEVIS" name="Datevis" />
<return-property column="INTERVENTION" name="Intervention" />
<return-property column="IDFACTURE" name="Idfacture" />
<return-property column="STATUT" name="Statut" />
<return-property column="NOFACTURE" name="Nofacture" />
<return-property column="NODEVIS" name="Nodevis" />
<return-property column="LIVRE" name="Livre" />
<return-property column="NOCOMMANDE" name="Nocommande" />
<return-property column="COMPTABILISEE" name="Comptabilisee" />
<return-property column="RECUP" name="Recup" />
<return-property column="MASQUE" name="Masque" />
</return>
exec CO_Visites_Treeview_Sel :Idclient, :Idmagasin, :Autre, :Tous
</sql-query>
</hibernate-mapping>
我创建了一个bean班级。 在这种情况下,结果将具有强类型对象,但我有一些一致性问题。 但我没有真正的标识符,所以如果有两个 Idvisite,第二个将被忽略。 我尝试创建一个复合键,但它不起作用。
<composite-id>
<key-property name="Idvisite" column="IDVISITE" type="string" />
<key-property name="Idfacture" column="IDFACTURE" type="string" />
</composite-id>
我有一个错误:
could not execute query
[ exec CO_Visites_Treeview_Sel @p0, @p1, @p2, @p3 ]
Name:Idclient - Value:036000004130 Name:Idmagasin - Value:36 Name:Autre - Value:False Name:Tous - Value:True
[SQL: exec CO_Visites_Treeview_Sel @p0, @p1, @p2, @p3]
有人可以告诉我该怎么做吗?
问候
Hello
I try to use stored procedure in nhibernate and I found some methods :
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<sql-query name="CO_Visites_Treeview_Sel">
exec CO_Visites_Treeview_Sel :Idclient, :Idmagasin, :Autre, :Tous
</sql-query>
</hibernate-mapping>
If I want to use the data I will use :
var query = session.GetNamedQuery("CO_Visites_Treeview_Sel");
query.SetString("Idclient", lstClients.SelectedValue.ToString());
query.SetInt32("Idmagasin", 36);
query.SetBoolean("Autre", false);
query.SetBoolean("Tous", true);
var results = query.List();
In that case I won't have intellisence neither result['colName']
I use another method :
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernate.DataAccess.Models.Visites_Treeview,NHibernate.DataAccess" lazy="true">
<id name="Idvisite" column="IDVISITE" type="string">
<generator class="assigned" />
</id>
<property column="NOMMAGASIN" name="Nommagasin" type="string" />
<property column="DATEVIS" name="Datevis" type="DateTime" />
<property column="INTERVENTION" name="Intervention" type="Boolean" />
<property column="IDFACTURE" name="Idfacture" type="string" />
<property column="STATUT" name="Statut" type="byte" />
<property column="NOFACTURE" name="Nofacture" type="int" />
<property column="NODEVIS" name="Nodevis" type="int" />
<property column="LIVRE" name="Livre" type="Boolean" />
<property column="NOCOMMANDE" name="Nocommande" type="int" />
<property column="COMPTABILISEE" name="Comptabilisee" type="Boolean" />
<property column="RECUP" name="Recup" type="Boolean" />
<property column="MASQUE" name="Masque" type="Boolean" />
</class>
<sql-query name="CO_Visites_Treeview_Sel">
<return alias="Visites_Treeview" class="NHibernate.DataAccess.Models.Visites_Treeview,NHibernate.DataAccess">
<return-property column="NOMMAGASIN" name="Nommagasin" />
<return-property column="IDVISITE" name="Idvisite" />
<return-property column="DATEVIS" name="Datevis" />
<return-property column="INTERVENTION" name="Intervention" />
<return-property column="IDFACTURE" name="Idfacture" />
<return-property column="STATUT" name="Statut" />
<return-property column="NOFACTURE" name="Nofacture" />
<return-property column="NODEVIS" name="Nodevis" />
<return-property column="LIVRE" name="Livre" />
<return-property column="NOCOMMANDE" name="Nocommande" />
<return-property column="COMPTABILISEE" name="Comptabilisee" />
<return-property column="RECUP" name="Recup" />
<return-property column="MASQUE" name="Masque" />
</return>
exec CO_Visites_Treeview_Sel :Idclient, :Idmagasin, :Autre, :Tous
</sql-query>
</hibernate-mapping>
I created a bean class.
In that case results will have strongly typed object but I have some coherency problem.
But I have no real identifier so if there is two Idvisite, the second will be ignored.
I tryed to create a composite key but it doesn't work.
<composite-id>
<key-property name="Idvisite" column="IDVISITE" type="string" />
<key-property name="Idfacture" column="IDFACTURE" type="string" />
</composite-id>
And I've an error :
could not execute query
[ exec CO_Visites_Treeview_Sel @p0, @p1, @p2, @p3 ]
Name:Idclient - Value:036000004130 Name:Idmagasin - Value:36 Name:Autre - Value:False Name:Tous - Value:True
[SQL: exec CO_Visites_Treeview_Sel @p0, @p1, @p2, @p3]
Can someone tell me how to do ?
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个,你的映射:-
使用 SetResultTransformer...
而你的类是:-
HTH
Try this, your mapping:-
use SetResultTransformer...
and YOURCLASS is:-
HTH