views:

11

answers:

0

I thought I understood what I was doing, and I swear this used to work when I used it in my last project!

I have an abstract class Enity that I use as a base class for all my DomainModel classes when working with NHibernate. The class is defined as:

   public abstract class Entity<TKey> where TKey : IComparable
{
    public abstract TKey DEFAULTKEY { get; }
    public virtual TKey Id { get; protected set; }

}

I then derive two classes from that, EntityWithIntID and EntityWithStringID:

   public class EntityWithIntID : Entity<int>
{
    public override int DEFAULTKEY { get { return 0; } }

    public EntityWithIntID()
    {
        Id = DEFAULTKEY;
    }
}

public class EntityWithStringID : Entity<string>
{
    public override string DEFAULTKEY
    {
        get { return string.Empty; }
    }

    public EntityWithStringID()
    {
        Id = DEFAULTKEY;
    }
}

And then I derive all my POCO objects from one of the other class, according to whether the underlying DB table needs an integer or string primary key.

But all of a sudden, when I AutoMap these classes in Fluent NHibernate, I'm getting an exception because the POCO object is ending up with TWO properties named DEFAULTKEY, apparently one from EntityWithIntID, and one from Entity. (In the particular case I'm debugging, they declaring types of the two DEFAULTKEY properties are CVR.DomainModels.Entity'1 and CVR.DomainModels.EntityWithIntID) And Fluent NHibernate is (naturally) throwing an exception when it tries to add the second DEFAULTKEY property.

I thought the "override" in the derived types would hide the abstract DEFAULTKEY property in the Entity class. What am I doing wrong, and how can I achieve the result I'm after?

Thanks.