C# nHibernate集只给出一个结果

C# nHibernate集只给出一个结果,c#,asp.net,nhibernate,nhibernate-mapping,set,C#,Asp.net,Nhibernate,Nhibernate Mapping,Set,我必须映射类: <class name="Business.DomainObjects.Institutions.Institutions, Business.DomainObjects" table="Institutions" lazy="false" mutable="false" > <id name="Id" access="field.camelcase-underscore" column="ID"> <generator class="i

我必须映射类:

<class name="Business.DomainObjects.Institutions.Institutions, Business.DomainObjects"
    table="Institutions" lazy="false" mutable="false" >
<id name="Id" access="field.camelcase-underscore" column="ID">
  <generator class="identity" />
</id>

<property name="Caption" type="String" access="field.camelcase-underscore" column="Name" not-null="true"/>
<property name="AddressLine" type="String" access="field.camelcase-underscore" column="AddressLine" not-null="true" />
<property name="Phone" type="String" access="field.camelcase-underscore" column="Phone" not-null="false" />
<set name="WorkTime" cascade="none" fetch="join">
  <key column="ID" not-null="true"/>
  <one-to-many class="Business.DomainObjects.Institutions.WorkHours, Business.DomainObjects"/>
</set>
机构映射类代码:

public class Institution
{
    private int _id = 0;
    private string _caption = null;
    private string _addressLine = null;
    private string _phone = null;
    private ICollection<WorkHours> _workTime = null;

    public Institution(){}
    public int Id { get { return _id; } internal set { _id = value; } }
    public string Caption { get { return _caption; } set { _caption = value; } }
    public string AddressLine { get { return _addressLine; } set { _addressLine = value; } }
    public string Phone { get { return _phone; } set { _phone = value; } }
    public ICollection<WorkHours> WorkTime { get { return _workTime; } set { _workTime = value; } }
}
公共类机构
{
私有int_id=0;
私有字符串_caption=null;
私有字符串_addressLine=null;
私有字符串_phone=null;
私有ICollection_workTime=null;
公共机构(){}
公共int Id{get{return}Id;}内部集合{{u Id=value;}
公共字符串标题{get{return{u Caption;}set{{u Caption=value;}}
公共字符串地址行{get{return{U AddressLine;}集合{U AddressLine=value;}}
公共字符串Phone{get{return{u Phone;}set{{u Phone=value;}}
公共ICollection工作时间{get{return}u WorkTime;}set{{u WorkTime=value;}}
}
正如你们所看到的,我已经在机构课程中设置了,但当我选择时,我只得到一个工作时间记录,而应该有7个。它生成良好的sql并选择必要的记录,同时在ManagementStudio中执行。我试着用袋子代替布景,但我7次都得到了同样的记录。也许有人知道问题出在哪里


好的,我稍微更改了我的映射:

<class name="Business.DomainObjects.Institutions.Institutions, Business.DomainObjects"
    table="Institutions" lazy="false" mutable="false" >
<id name="Id" access="field.camelcase-underscore" column="InstitutionID">
  <generator class="identity" />
</id>

<property name="Caption" type="String" access="field.camelcase-underscore" column="Name" not-null="true"/>
<property name="AddressLine" type="String" access="field.camelcase-underscore" column="AddressLine" not-null="true" />
<property name="Phone" type="String" access="field.camelcase-underscore" column="Phone" not-null="false" />
<set name="WorkTime" cascade="none" fetch="join">
  <key column="InstitutionID" not-null="true"/>
  <one-to-many class="Business.DomainObjects.Institutions.WorkHours, Business.DomainObjects"/>
</set>

<class name="Business.DomainObjects.Institutions.WorkHours, Business.DomainObjects" 
table="WorkHours" lazy="false" mutable="false" >
<id name="Id" access="field.camelcase-underscore" column="WorkHoursID">
  <generator class="identity" />
</id>
<property name="Weekday" type="int" access="field.camelcase-underscore" column="Weekday" not-null="true" />
<property name="OpenFrom" type="DateTime" access="field.camelcase-underscore" column="OpenFrom" not-null="true" />
<property name="OpenTill" type="DateTime" access="field.camelcase-underscore" column="OpenTill" not-null="true" />
<property name="OpenTime" type="String" access="field.camelcase-underscore" column="OpenTime" not-null="true" />
<many-to-one name="Institution" class="Business.DomainObjects.Institutions.Institution, Business.DomainObjects" column="InstitutionID" />
</class>

但我仍然有同样的问题。

这看起来很可疑:

<key **column="ID"** not-null="true"/>

它应该映射到WorkHours表中的外键列,因此可能类似于InstitutionID的内容这看起来很可疑:

<key **column="ID"** not-null="true"/>


它应该映射到WorkHours表中的外键列,因此可能类似InstitutionID的内容看起来不正确:

   



Column=XX在这两种情况下,请参考工时表中的外键列。尝试类似Column=InstitutionID的方法,这些方法看起来不正确:

   



Column=XX在这两种情况下,请参考工时表中的外键列。试试Column=InstitutionID之类的方法,我发现了我的问题。我必须更改我的工作时间映射并添加此项

<composite-id access="field.camelcase-underscore">
  <key-many-to-one
      class="Business.DomainObjects.Institutions.Institution, Business.DomainObjects"
      name="Institution"
      column="InstitutionID"
      access="field.camelcase-underscore"
  />
  <key-property
      name="Weekday"
      type="int"
      access="field.camelcase-underscore"
      column="Weekday"
  />
</composite-id>

而不是:

<id name="Id" access="field.camelcase-underscore" column="WorkHoursID">
  <generator class="identity" />
</id>
<property name="Weekday" type="int" access="field.camelcase-underscore" column="Weekday" not-null="true" />


它现在工作得很好。

我发现了我的问题。我必须更改我的工作时间映射并添加此项

<composite-id access="field.camelcase-underscore">
  <key-many-to-one
      class="Business.DomainObjects.Institutions.Institution, Business.DomainObjects"
      name="Institution"
      column="InstitutionID"
      access="field.camelcase-underscore"
  />
  <key-property
      name="Weekday"
      type="int"
      access="field.camelcase-underscore"
      column="Weekday"
  />
</composite-id>

而不是:

<id name="Id" access="field.camelcase-underscore" column="WorkHoursID">
  <generator class="identity" />
</id>
<property name="Weekday" type="int" access="field.camelcase-underscore" column="Weekday" not-null="true" />


它现在运行得很好。

您是否将机构映射到WorkHours对象?你能给我们看看db表中的数据吗?我们也能看看你的映射类代码吗?你把机构映射到WorkHours对象了吗?你能给我们看看db表中的数据吗?我们也能看看你的映射类代码吗。