0

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 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.

user229044
  • 232,980
  • 40
  • 330
  • 338
big_tommy_7bb
  • 1,257
  • 2
  • 21
  • 37

1 Answers1

1

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.

Community
  • 1
  • 1
DanP
  • 6,310
  • 4
  • 40
  • 68