I have this clases mapped on NHibernate 3.2 with FluentNHibernate 1.3:
public class ClassA
{
public virtual Int32 Id{ get; }
....
public ICollection<ClassB> ClassesB { get; }
public ICollection<ClassC> ClassesC { get; }
}
public class ClassB
{
public virtual Int32 Id{ get; }
....
public ICollection<ClassA> ClassesA { get; }
public ICollection<ClassC> ClassesC { get; }
}
public class ClassC
{
public virtual Int32 Id{ get; }
....
public ICollection<ClassA> ClassesA { get; }
public ICollection<ClassB> ClassesB { get; }
}
All the mappings works correctly and as spected. But I need to make queries with LINQ that returns, for example, all the ClassC instances in a given ClassB or ClassA instances, and viceversa. I need to do this without loading any ClassB or ClassA instances before getting the list of ClassC, just make the query with the ID of the instance.
I know that I can load, for example, a ClassB instance and then get the ClassesC collection, but with my application desing I must do this without doing that, I'll use this for things like paging on a Grid, and other operations diferent from the paging.
On pure SQL I can do that with a simple join query, but I dont know how to do that with LINQ. And I dont want the option of HQL or ICriteria, it must be done with LINQ (Extensions preferable) because the application uses plugins that must not have awareness of the NHibernate presence. The plugin receives a IQueryable instance to make the queries (this allow us to easely port the core application to other data base schema, like NoSQL or something else without even recompilation of the plugins or other parts of the aplication).
Thanks for your help in advance.