I have quite a complex entity structure where several classes inherit from a base class, hence choosing a table per-subclass structure in nhibernate.
BaseProject
ProjectA : BaseProject
ProjectB : BaseProject
ProjectC : BaseProject
ProjectD : BaseProject
I want to search where one开发者_如何学Python of the criteria will be ProjectType. I'm trying to avoid writing a seperate query specification for each ProjectType.
Does anyone know how this might be achieved? Is it even something Linq to nHibernate can do, as I think it isn't complete yet.
I was expecting something like x => x.GetType() == typeof(ProjectTypeA)
to work but it doesn't.
Unfortunately, the way you've described is the only way to do this using the current Linq provider. You'll need to expose a property (likely an enumeration) mapped with NHibernate that is exposed by each sub class. One useful trick is to map this property with update=false
to ensure it is never changed.
You can see my answer to a similar question here for further details.
精彩评论