Basically what i am trying to do is join two tables on foreign keys. I have this query:
var result =
_session.QueryOver(() => contentReferenceAlias)
.Inner.JoinAlias(() => contentReferenceAlias.ContentReference, () => contentLibrarySearchAlias.ContentReference)
.Where(() => contentReferenceAlias.ToLanguage.Id == languageId && contentReferenceAlias.ContentReference.Id == contentLibrarySearchAlias.ContentReference.Id)
.SelectList(list => list
.Select(() => contentReferenceAlias.ContentReference)
.Select(() => contentLibrarySearchAlias.ContentReference)
.Select(() => contentReferenceAlias.ContentReference.Id).WithAlias(() => resultAlias.ContentReferenceId)
.Select(() => contentReferenceAlias.ContentReference.Id).WithAlias(() => resultAlias.ContentReferenceId)
.Select(() => contentReferenceAlias.OrderedFrom).WithAlia
The SQL im trying to recreate:
SELECT A.OrderedFrom, C.LastOrdered, A.ContentReferenceId, B.Title FROM TranslationContentReference A
INNER JOIN TranslationOrder C ON (A.TranslationOrderId = C.Id)
INNER JOIN ContentLibrarySearch B ON (A.ContentReferenceId = b.ContentReferenceId)
WHERE A.ToLanguageId = 'xxxx-xxxx-xxxx-xxxx-xxxx'
If I do understand your scenario correctly, join over man-in-the-middle (foreign key reference) cannot be achieved via QueryOver API. NHibernate needs to know pathes all the way down, So if there is no explicit mapping from
TranslationContentReferencethroughContentReferencetoContentLibrarySearch, then we cannot create correct JoinAliases.So, first option is to extend the man-in-the-middle object
Then we can navigate (create pathes)
TranslationContentReferencetoContentReferenceContentReferencetoContentLibrarySearchThe second option, which is less NHibernate and more SQL, is to create
ISQLQuery