views:

319

answers:

2

How does one create a mapping file for a generic class in NHibernate. Say I have a class Foo How would it look in the mapping document? class name="mydll.Foo ???? , mydll" ...

I know if it was a Foo it would be: class name="mydll.Foo`1[[mydll.Fee, mydll]], mydll"

Would it be something like: class name="mydll.Foo`1[[mydll.Fee, mydll],[mydll.Fi, mydll]], mydll" (I tried this, but it didn't work.

A: 

I might be in over my head here (Just started doing NHibernate 3 days ago), but does it give meaning to map an abstract class? You cant instantiate an abstract class, so, why would you map it to data?

My best guess is that you have to map your subclasses to the data they need, and make public / protected setter's on your baseclass, to map these too. This would ofc mean a lot of copy-pasting since youd map your base class the same way for all (in a perfect world) subclasses.

[EDIT] Found this: http://stackoverflow.com/questions/281247/nhibernate-one-base-class-several-mappings

cwap
A: 

The correct mapping would be: class name="mydll.Foo`2[[mydll.Fee, mydll],[mydll.Fi, mydll]], mydll"

There are two generic elements so change the 1 to a 2. Not sure is this is valid on the name attribute of the class, but it works for the collection-type attribute