As you may have guessed, you can't use polymorphic queries for properties
that are only defined in one of the classes.
If you desperately needed to make this one query, you could hack some
complex criteria with subqueries, or just write a SQL query with UNION.
However, it's probably cleaner to do it with two queries and join them with
LINQ-to-objects.
Since the Criteria API is actually more useful for search (where the
parameters vary), and you seem to have a pretty static query here, I'd go
one step further and use also NHibernate.Linq (you could also use QueryOver
with NH 3.x)
So, your whole query would be:
var listOfReservables = Session.Linq<FrameworkContract>().Where(fc =>
fc.Quantity > 0 && fc.Status == "Confirmed")
.ToList().Cast<Reservable>()
.Concat(
Session.Linq<InventoryStock>().Where(fc =>
fc.Quantity > 0)
.ToList().ToList().Cast<Reservable>())
Diego
On Mon, Mar 8, 2010 at 13:13, Patrik Lowendahl
<[email protected]>wrote:
> Hello,
>
> I have a scenario where I fetch data from two different tables into a
> "Reservable". You can reserve from inventory stock or from framework
> contracts. This is mapped using Table per concrete class strategies.
> However, I found a challenge. There is slighty different rules in what's
> acceptable as a reservable. StockInventory it's sufficient with quantity > 0
> but for framework contracts it need to be cofirmed as well.
>
> I would like to do something like:
>
> var listOfReservables = Session.CreateCriteria(typeof (Reservable))
> .Add(Restrictions.Gt("Quantity", 0))
> .Add(Restrictions.Eq("Status", "Confirmed"))
> .List<Reservable>();
>
> But this isn't possible in it's current form since StockInventory doesn't
> have a Status, just the Framework Contract. Is this possible? Or do I need
> to create two separate queries for each concrete class and joint them
> myself?
>
> --
> Patrik Löwendhl
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.