This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have an entity called 'MyBassItem' and am using single table inheritance. I would like the bass class to be abstract. When I mark the bass class as abstract I lose the collection 'MyBassItems' from the unit of work. I end up with a separate collection for each of the derived types which is great but I would still like the master collection of all of them. Is this possible? |
|
|
Yes we deliberately dont generate the queryable properties for abstract base classes but with STI querying against the base type will still work as long as every entity can ultimately be materialized into a concrete derived class (e.g. you dont have any discriminator values that dont map to one of the derived types leading to us trying to materialize an abstract instance!). You can "add this back in" to the UnitOfWork by extending the typed UnitOfWork class definition with your own partial and then adding in a new property to give you a collection of your abstract type, it should look something like this:
|
|
|
Thanks Jeremy that works well. On a related note I notice that when I do this:
and then (before saving) query:
then
however the item does exist in the
I have also had to adjust my UnitOfWork mock to deal with the same situation. There I can check if it is a derived type and add it to the bass class' collection as well. Any thoughts? |
|
|
Loading from those IQueryables (or doing a UnitOfWork.Find call) issues a database query to find the result set so only persisted entities are considered. If you want to include newly added entities (e.g. the in-memory set) you will need to merge these into the results yourself, you can enumerate these out of the identity map by doing something like this:
|
|