I have a table in C# and ASP.net that references a list of another table where several vehicle registrants are mapped to a single vehicle. I do not want to go through the whole collection of vehicle registrants by accessing their individual members (e.g. vehicleRegistrantsAlias[0]), because I do not know how many there will be.
Do I need to do this in two queries? I really would like to do it all in one. I have the parent class as vehicle and a child collection of vehicle registrants. Vehicle registrant is a base type and under a vehicle registrant is the owner and operator. I also want to pull information form other child tables. I am joining from vehicle to vehicleRegistrants which works fine; however, I also want to pull owner and operant.
Vehicle vehicleAlias = null;
List<VehicleRegistration> vehicleRegistrationsAlias = null;
List<VehicleRegistrant> vehicleRegistrantsAlias = null;
.JoinAlias(() => vehicleAlias.VehicleRegistrations, () => vehicleRegistrationsAlias)
.JoinAlias(() => vehicleAlias.VehicleRegistrants, () => vehicleRegistrantsAlias)
//from vehicle registrants
.JoinAlias(() => vehicleRegistrantsAlias[0]., () => vehicleSuspensionTypeAlias)
You can use LINQ to NHibernate as well, it usually makes the queries easier to understand than the QueryOver API.
Based on the comments, I guess you want a function with the following signature:
Or, if you have a relationship in the direction from
VehicleRegistrantto its parentVehicle, this would also workI’m not sure if this is exactly what you wanted, but I believe you get the idea.
FetchMany(x => x.VehicleRegistrants)tells NHibernate to also fetch all theVehicleRegistrantsfor eachVehiclein the result set and the followingThenFetch(x => x.Owner)tells “and for each of thoseVehicleRegistrants, also fetch itsOwner“.Does this help?