NHibernate Bag系列是空的

时间:2011-04-18 21:26:04

标签: nhibernate nhibernate-mapping

当我尝试使用NHibernate包时,我有一个奇怪的问题

映射

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="FMG.APO.Dao.Domain" assembly="FMG.APO.Dao">
    <class name="Constraint" table="rConstraintItems" lazy="false">
        <id name="Id" type="Int32" unsaved-value="0">
            <column name="ConstraintItemID" sql-type="int" not-null="true"  />
            <generator class="native" />
        </id>
        <many-to-one name="ConstraintGroup" class="ConstraintGroup">
            <column name="ConstraintGroupID" sql-type="int" not-null="false" />
        </many-to-one>

        <many-to-one name="Fund" class="Fund">
            <column name="FundID" sql-type="int" not-null="true" />
        </many-to-one>
        <property name="LowerLimit" type="double">
            <column name="LowerLimit" sql-type="decimal" not-null="true"/>
        </property>
        <property name="UpperLimit" type="double">
            <column name="UpperLimit" sql-type="decimal" not-null="true"/>
        </property>
        </class>
</hibernate-mapping>

private int id;

public Constraint() { }
public Constraint(Fund fund, double lowerLimit, double upperLimit)
{
    this.fund = fund;
    this.lowerLimit = lowerLimit;
    this.upperLimit = upperLimit;
}

public int Id
{
    get { return id; }
    set { id = value; }
}

private Fund fund;

public Fund Fund
{
    get { return fund; }
    set { fund = value; }
}

private ConstraintGroup constraintGroup;
public ConstraintGroup ConstraintGroup
{
    get { return constraintGroup; }
    set { constraintGroup = value; }
}

private double lowerLimit;

public double LowerLimit
{
    get { return lowerLimit; }
    set { lowerLimit = value; }
}
private double upperLimit;

public double UpperLimit
{
    get { return upperLimit; }
    set { upperLimit = value; }
}

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="FMG.APO.Dao.Domain" assembly="FMG.APO.Dao">
    <class name="ConstraintGroup" table="rConstraintGroups" lazy="false">
        <id name="Id" type="Int32" unsaved-value="0">
            <column name="ConstraintGroupID" sql-type="int" not-null="true"  />
            <generator class="native" />
        </id>
        <property name="PlanID" type="Int32">
            <column name="PlanID" sql-type="int" not-null="true"/>
        </property>
        <property name="GroupDescr" type="String">
            <column name="GroupDescr" length="100" sql-type="nvarchar"/>
        </property>
        <bag name="Constraints" inverse="true" lazy="true" cascade="all">
            <key column="ConstraintGroupID"/>
            <one-to-many class="Constraint" />
        </bag>
    </class>
</hibernate-mapping>

上课

 public class ConstraintGroup
    {
 private int id;

    public int Id
    {
        get { return id; }
        set { id = value; }
    }

    private int planID;

    public int PlanID
    {
        get { return planID; }
        set { planID = value; }
    }
    private string groupDescr;

    public string GroupDescr
    {
        get { return groupDescr; }
        set { groupDescr = value; }
    }


    protected IList<Constraint> constraints;
    public IList<Constraint> Constraints
    {
        get
        {
            if (constraints == null)
            {
                constraints = new List<Constraint>();
            }
            return constraints;
        }
        set { constraints = value; }
    }
}

我有2个相同的数据库(我已反复检查并比较它们)。包在我的测试数据库中填充,但在我的生产数据库中是空的。有人可以帮我解决这个问题吗?我真的被困了

0 个答案:

没有答案