I have this tables:
Person -> PersonFavorites, PersonCompany
PersonCompany -> Company
I have now to do the following select with NHibernate and QueryOver:
select * from Person
inner join PersonFavorites on Person.Id = PersonFavorites.PersonId
inner join PersonCompany on Person.Id = PersonCompany.PersonId
inner join Company on Company.Id = PersonCompany.CompanyId
where ...
Can someone give me a sample, how I can do that? - My Problem is, that I have to join multiple Tables Person -> PersonCompany -> Company. The Join Person -> PersonCompany and Person -> PersonFavorites are no problem - but the next step from PersonCompany -> Company.
Low Flying Pelican
Mapping should be similar to the following:
Entities
class Person
{
Collection<PersonFavorites> favorites;
Collection<PersonCompany> companies;
}
class PersonFavorite
{
Person person;
Favorite favorite;
}
class PersonCompany
{
Person person;
Company company;
}
Query
Person personAlias = null;
PersonFavorites personfavouriteAlias = null;
PersonCompany personCompanyAlias = null;
Company companyAlias = null;
Favorite favouriteAlias = null;
var query = Session.QueryOver<Person>(() => personAlias)
.joinAlias(() => personAlias.favorites, () => personfavouriteAlias)
.joinAlias(() => personAlias.companies, () => personCompanyAlias)
.joinAlias(() => personfavouriteAlias.Favourite, () => favouriteAlias)
.joinAlias(() => personCompanyAlias.Company, () => companyAlias)
来源:https://stackoverflow.com/questions/12652087/join-multiple-tables-with-nhibernate-and-queryover