Using v2.6, .NET 2.0, SelfServicing...
I'm having problems with this query:
select BOOK_TOC.*, versionOuter.* from BOOK_TOC_VERSION as versionOuter
inner join
(
select BOOK_TOC_ID, max(VERSION_ID) as MAX_VERSION_ID
from BOOK_TOC_VERSION
where VERSION_ID <= @versionId
group by BOOK_TOC_ID
)
as versionInner
on
versionOuter.BOOK_TOC_ID = versionInner.BOOK_TOC_ID
and
versionOuter.VERSION_ID = versionInner.MAX_VERSION_ID
inner join
BOOK_TOC on versionOuter.BOOK_TOC_ID = BOOK_TOC.BOOK_TOC_ID
-- plus varying WHERE clauses
-- e.g. where BOOK_TOC_VERSION.ANOTHER_FIELD = 1234
-- e.g. where BOOK_TOC.YET_ANOTHER_FIELD = 'abc'
Specifically, the problem is the inner join to the subquery. For that I was trying dynamic relations and derived tables but that usually got me as far as:
select from (s) inner join t
whereas I am trying to get:
select from t inner join(s)
The main query is executed on a BookTocCollection, and I have a prefetch and relation to get the BookTocVersionCollection. So the current result is:
PrefetchPath prefetch = new PrefetchPath(EntityType.BookTocEntity);
prefetch.Add(BookTocEntity.PrefetchPathBookTocVersion);
RelationCollection relations = new RelationCollection();
relations.Add(BookTocEntity.Relations.BookTocVersionEntityUsingBookTocId);
/* something needs to go here to make magic :) */
BookTocCollection bookTocCollection = new BookTocCollection();
bookTocCollection.GetMulti(
predicate, //my varying where clause passed into the method
0,
new SortExpression(BookTocVersionFields.SiblingOrder | SortOperator.Ascending),
relations,
prefetch);
Any assistance will be much appreciated.
Thanks