Мне нужно сопоставить классы:
<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>
и
<class name="Business.DomainObjects.Institutions.WorkHours, Business.DomainObjects"
table="WorkHours" lazy="false" mutable="false" >
<id name="Id" access="field.camelcase-underscore" column="ID">
<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="ID" />
</class>
Код класса отображения:
public class WorkHours
{
private int _id = 0;
private int _weekday = 0;
private DateTime _openFrom = DateTime.MinValue;
private DateTime _openTill = DateTime.MinValue;
private string _openTime = null;
private Institution _institution = null;
public WorkHours(){}
public int Id { get { return _id; } internal set { _id = value; } }
public string OpenTime { get { return _openTime; } set { _openTime = value; } }
public DateTime OpenTill { get { return _openTill; } set { _openTill = value; } }
public DateTime OpenFrom { get { return _openFrom; } set { _openFrom = value; } }
public int Weekday { get { return _weekday; } set { _weekday = value; } }
public Institution Institution { get { return _institution; } set { _institution = value; } }
}
Код класса отображения учреждения:
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; } }
}
Как вы видите, я установил в классе Institutions, но когда я выбираю, я получаю только одну запись WorkHours, в то время как должно быть 7. Он генерирует хороший sql и выбирает необходимые записи, выполняя его в Management Studio.Я пытался использовать сумку вместо набора, но я получаю одну и ту же запись 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>
Но у меня все еще есть та же проблема.