我的QueryOver出現問題,我不明白爲什麼。我的查詢返回viewmodel對象ContactInfo。我在Employee屬性上遇到此錯誤:「無法找到屬性的setter」。我如何在ContactInfo中填充Employee屬性?我究竟做錯了什麼?NHibernate的QueryOver使用投影在父對象中填充屬性對象
視圖模型對象:
public class ContactInfo
{
public EmployeeInfo Employee { get; set; }
public string Email { get; set; }
public string InternalTelephone { get; set; }
}
查詢
public override ContactInfo Execute()
{
ContactInfo r = null;
EmployeeInfo ei = null;
var result = Session.QueryOver<Job>()
.JoinAlias(j => j.EmployeeInfo,() => ei)
.Where(j => j.EmployeeInfo.Id == _employeeId)
.Select(
Projections.Property<Job>(j => ei.Id).WithAlias(() => r.Employee.Id),
Projections.Property<Job>(j => ei.FirstName).WithAlias(() => r.Employee.FirstName),
Projections.Property<Job>(j => ei.LastName).WithAlias(() => r.Employee.LastName),
Projections.Property<Job>(j => ei.ReferenceCode).WithAlias(() => r.Employee.ReferenceCode),
Projections.Property<Job>(j => j.Telefoon).WithAlias(() => r.InternalTelephone)
)
.TransformUsing(Transformers.AliasToBean<ContactInfo>())
.Take(1)
.SingleOrDefault<ContactInfo>();
var email = Session.QueryOver<Employee>()
.Where(e => e.Id == _employeeId)
.Select(e => e.Email)
.SingleOrDefault<string>();
result.Email = email;
return result;
}
}
我會說解決方案在這裏:http://stackoverflow.com/a/26779306/1679310或這裏http://stackoverflow.com/a/26901453/1679310 –
@RadimKöhler我看到了這些解決方案,但你的DeepTransformer類給了我一個dictionary.Is()中的錯誤他不認識這個函數。任何解決這個問題? –