我正在使用 Linq to NHibernate 开发 C#。
我定义了 2 组类和映射:
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
}
<hibernate-mapping ...>
<class name="Example.Employee, Example">
<id name="ID">
<generator class="assigned" />
</id>
<property name="Name" length="100" not-null="true" />
</class>
</hibernate-mapping>
public class Department
{
public DepartmentID ID { get; set; }
public int EmployeeID
{
get { return this.ID.Employee.ID; }
set { }
}
public string Name { get; set; }
}
<hibernate-mapping ...>
<class name="Example.Department, Example">
<composite-id name="ID">
<key-many-to-one name="Employee" column="EmployeeID" />
<key-property name="StartDate" />
</composite-id>
<property name="EmployeeID" not-null="true"/>
<property name="Name" not-null="true"/>
</class>
</hibernate-mapping>
并执行以下查询:
var result =
from x in employeeQueryable
join y in departmentQueryable on x.ID equals y.EmployeeID
where y.ID.StartDate <= DateTime.Parse("2012/9/10")
group y by y.EmployeeID into xy
select xy.Max(a => a.ID.StartDate);
但此查询引发以下异常:
无法识别查询源。ItemName = a,ItemType = Example.Department,Expression = from Department a in [x]
如果employeeQueryable
anddepartmentQueryable
是数组类型(不是 linq to NHibernate),那么这个查询不会抛出异常。
我应该怎么办?