I'm having a problem with my QueryOver and I don't understand why. My query returns the viewmodel object ContactInfo. I get this error on the Employee property: "could not find setter for property". How can I fill the Employee property within ContactInfo? What am I doing wrong?
ViewModel Object:
public class ContactInfo
{
public EmployeeInfo Employee { get; set; }
public string Email { get; set; }
public string InternalTelephone { get; set; }
}
Query
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;
}
}