I have been trying to find a way to do this query using a NHibernate criteria (preferred) or HQL, with no luck.
Here is the query:
select COUNT(sa.Id) from Accounts a
join Sources s on a.Id = s.Account_Id
join SpecialArticles sa on sa.SpecialSource_Id = s.Id
Notes:
- SpecialSource is subclass of Source and is mapped as a JoinedSubClass
- SpecialArticle is a subclass of Article and is mapped as a JoinedSubClass
Here is the class model psudo-code:
class Account
{
Guid _id;
}
class Source
{
Guid _id;
Account _account;
}
class Article
{
Guid _id;
Source _source;
}
class SpecialSource : Source
{
Guid _id;
// ... subclass specific fields
}
class SpecialArticle : Article
{
Guid _id;
// ... subclass specific fields
}
And the aim is basically to count the number SpecialArticles for an Account.
Any help is appreciated!