I have a generic class Lookup which contains code/value properties. The table PK is category/code. There are subclasses for each category of lookup, and I've set the discriminator column in the base class and its value in the subclass. See example below (only key pieces shown):
public class Lookup { public string Category; public string Code; public string Description; }
public class LookupClassMap { CompositeId() .KeyProperty(x => x.Category, "CATEGORY_ID") .KeyProperty(x => x.Code, "CODE_ID"); DiscriminateSubclassesBasedOnColumn("CATEGORY_ID"); }
public class MaritalStatus: Lookup {}
public class MartialStatusClassMap: SubclassMap { DiscriminatorValue(13); }
This all works. Here's the problem. When a class has a property of type MaritalStatus, I create a reference based on the contained code ID column ("MARITAL_STATUS_CODE_ID"). NHibernate doesn't like it because I didn't map both primary key columns (Category ID & Code ID). But with the Reference being of type MaritalStatus, NHibernate should already know what the value of the category ID is going to be, because of the discriminator value.
What am I missing?