我遇到了nhibernate映射的问题。我使用代码的 和 当我使用它时,将SCESL_SCESID列重命名为SCESL_CESSIONSLIGNES表中的IdCessionsLignes。我生成了hbm.xml文件,结果是:(第一次 和 任何想法?namespace NhibernateLiaisonBase
{
[Serializable]
public class Cessions
{
#region Public Properties
public virtual int IdCessions
{
get;
set;
}
public virtual DateTime CessionsDate
{
get;
set;
}
#endregion
}
public class CessionsMap : ClassMapping<Cessions>
{
public CessionsMap()
{
Id<int>(x => x.IdCessions, map => map.Column("SCES_ID"));
Property<DateTime>(x => x.CessionsDate, map => map.Column("SCES_DATE"));
Table("SCES_CESSIONS");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Mapping.ByCode.Conformist;
namespace NhibernateLiaisonBase
{
[Serializable]
public class CessionsLignes
{
#region Public Properties
public virtual int IdCessionsLignes
{
get;
set;
}
public virtual int QuantiteCessionsLignes
{
get;
set;
}
public virtual Cessions cessions
{
get;
set;
}
#endregion
}
public class CessionsLignesMap : ClassMapping<CessionsLignes>
{
public CessionsLignesMap()
{
Id<int>(x => x.IdCessionsLignes, map =>
{
map.Generator(NHibernate.Mapping.ByCode.Generators.Identity);
});
Property<int>(x => x.QuantiteCessionsLignes, map => map.Column("SCESL_QTE"));
ManyToOne<Cessions>(x => x.cessions, map => map.Column("SCESL_SCESID"));
Table("SCESL_CESSIONSLIGNES");
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" namespace="NhibernateLiaisonBase" assembly="NhibernateLiaisonBase" xmlns="urn:nhibernate-mapping-2.2">
<class name="Cessions" table="SCES_CESSIONS">
<id name="IdCessions" column="SCES_ID" type="Int32" />
<property name="CessionsDate" column="SCES_DATE" />
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" namespace="NhibernateLiaisonBase" assembly="NhibernateLiaisonBase" xmlns="urn:nhibernate-mapping-2.2">
<class name="CessionsLignes" table="SCESL_CESSIONSLIGNES">
<id name="IdCessionsLignes" type="Int32">
<generator class="identity" />
</id>
<property name="QuantiteCessionsLignes" column="SCESL_QTE" />
<many-to-one name="cessions" column="SCESL_SCESID" />
</class>
</hibernate-mapping>
答案 0 :(得分:3)
我想你忘记了身份地图中对Column
的号召:
Id<int>(x => x.IdCessionsLignes, map =>
{
map.Column("SCESL_SCESID")
.Generator(NHibernate.Mapping.ByCode.Generators.Identity);
});