私はクラスを持っています
public class HobbyHome:Establishment
{
public virtual ICollection<HobbyHomeAddress> HobbyHomeAddressList { set; get; }
public virtual ICollection<HobbyDeveloper> HobbyDeveloperList { set; get; }
public virtual ICollection<HobbyDetail> HobbyDetailList { set; get; }
}
趣味内詳細:
[Key]
public virtual int HobbyDetailID { get; set; }
// public virtual int HobbyId { get; set; }
public virtual HobbyMasters Hobbymaster { get; set; }
public virtual Course course { get; set; }
public virtual StudyMedium StudyMedium { get; set; }
public virtual decimal Fees { get; set; }
}
両方のテーブルにデータを保存できます...しかし、HobbyHomeIdを介して趣味の詳細をフェッチしている間...フィールドが見つからないため、エラーが発生します
Hobbyhome のマッピング ファイル:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly ="HobbyHomes" namespace="HobbyHomes.Model" >
<class name ="HobbyHome" table="HobbyHome">
<id name="EstablishmentId" column="HobbyHomeId">
<generator class="native"/>
</id>
<property name="Name"/>
<set name="HobbyHomeAddressList">
<key column="HobbyHomeId" foreign-key="fk_HobbyHomeAddress_HobbyHomeId"/>
<one-to-many class ="HobbyHomes.Model.HobbyHomeAddress"/>
</set>
<set name="HobbyDeveloperList">
<key column="HobbyHomeId" foreign-key="fk_HobbyDeveloper_HobbyHomeId"/>
<one-to-many class ="HobbyHomes.Model.HobbyDeveloper"/>
</set>
<set name="HobbyDetailList">
<key column="HobbyHomeId" foreign-key="fk_HobbyDetail_HobbyHomeId"/>
<one-to-many class ="HobbyHomes.Model.HobbyDetail"/>
</set>
</class>
</hibernate-mapping>
データを取得するための私の関数は次のとおりです。
public HobbyDetail FetchbyHobbyId(int id)
{
log.Debug("Start");
ISession session = DataAccessLayerHelper.OpenWriterSession();
ITransaction transaction = session.BeginTransaction();
HobbyDetail hobbydetail = null;
try
{
ICriteria criteria = session.CreateCriteria(typeof(HobbyDetail))
.Add(Restrictions.Eq("HobbyHomeId", id));
hobbydetail = criteria.UniqueResult<HobbyDetail>();
transaction.Commit();
}
catch (SessionException ex)
{
if (transaction != null && transaction.IsActive)
transaction.Rollback();
log.Error(ex);
hobbydetail = null;
}
finally
{
if (transaction != null)
transaction.Dispose();
if (session != null && session.IsConnected)
session.Close();
log.Debug("End");
}
return hobbydetail;
}
これで私を助けてください....