0

I'm working on C# with Linq to NHibernate.

I defined 2 sets of classes and mappings:

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>

and executed the following query:

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);

But this query throws following Exception:

Query Source could not be identified. ItemName = a, ItemType = Example.Department, Expression = from Department a in [x]

If employeeQueryable and departmentQueryable are array types (not linq to NHibernate), then this query doesn't throw an excepton.

What should i do?

ronalchn
  • 12,225
  • 10
  • 51
  • 61
katsu
  • 1

1 Answers1

0

get rid of EmployeeID in Department and use

var result =
    from d in departmentQueryable 
    where d.ID.StartDate <= new DateTime(2012, 9, 10)
    group d by d.ID.Employee.Id into g
    select g.Max(d => d.ID.StartDate);
Firo
  • 30,626
  • 4
  • 55
  • 94