gpt4 book ai didi

c# - Nhibernate通过代码映射,如何使用存储过程?

转载 作者:行者123 更新时间:2023-11-30 20:07:10 26 4
gpt4 key购买 nike

我通过代码使用 nhibernate 3.2 新功能映射(它工作得很好)。

例如:

[Serializable]
public class Profil
{
public virtual int Id
{
get;
set;
}
public virtual string Nom
{
get;
set;
}
}

public class ProfilMap : ClassMapping<Profil>
{
public ProfilMap()
{
Id<int>(x => x.Id, map =>
{
map.Generator(NHibernate.Mapping.ByCode.Generators.Identity);
});
Property<string>(x => x.Nom);
}
}

我现在想使用存储过程。对于旧版本的 nhibernate,我使用 hbm.xml 文件,如

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<sql-query name="FillNouveautes">
exec FillNouveautes :Idclient
</sql-query>
</hibernate-mapping>

我是这样用的:

    public void FillNouveautes(ISession session, int idClient)
{
var query = session.GetNamedQuery("FillNouveautes");
query.SetInt32("Idclient", idClient);
query.ExecuteUpdate();
}

有没有新语法?还是应该使用旧样式?

问候

最佳答案

我在 NHibernate 3.2 Mapping by convention (code) stored procedure 上找到了解决方案

我必须通过代码混合 hbm.xml 和映射。比照。 http://puredotnetcoder.blogspot.com/2011/07/mixed-mappings-with-hbm-and-mapping-by.html

现在我要测试一下

关于c# - Nhibernate通过代码映射,如何使用存储过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8786803/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com