嗨,我想在表之间执行连接,但我无法做到。
这是我的课程:
public class Person
{
public virtual LoginAccount LoginAccount { get; set; }
}
public class LoginAccount
{
//fields of LoginAccount
}
Person的映射文件
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly ="HobbyHomes" namespace ="HobbyHomes.Model" >
<class name ="Person">
<composite-id class="HobbyHomes.Model.LoginAccount" name="LoginAccount">
<key-property name="LoginAccountID">
<column name="LoginAccountID"></column>
</key-property>
</composite-id>
//other properties
</class>
现在这是我试图从 Person 获取 LoginAccount 值的内容:
public IList<Person> FetchPerson(ICollection<Learner> learner)
{
log.Debug("Started");
ISession session = DataAccessLayerHelper.OpenReaderSession();
IList<Person> person = null;
ITransaction transaction = null;
Disjunction dj = new Disjunction();
try
{
transaction = session.BeginTransaction();
person = session.CreateCriteria(typeof(Person), "person")
.CreateCriteria("person.LoginAccount", "LoginAccount", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
.List<Person>();
transaction.Commit();
}
catch (Exception ex)
{
if (transaction != null && transaction.IsActive)
transaction.Rollback();
log.Error(ex);
}
finally
{
if (transaction != null)
transaction.Dispose();
if (session != null && session.IsConnected)
session.Close();
}
log.Debug("End");
return person;
}
但是这样我只能获取 Person 类的字段,而不是 LoginAccount 类的字段。请帮助我。