trying to map through multiple interface inheritance

Devon Lazarus's Avatar

Devon Lazarus

27 May, 2010 10:32 PM via web

I've seen this post here that is loosely related to what I'm trying to accomplish:

http://support.fluentnhibernate.org/discussions/help/50-getting-obj...

I'm trying to map a EavAttribute<T>, that inherits Entity and implements IEavAttribute. I'm pretty sure the problem I'm having is related to the fact that IEavAttribute extends IEntity. I've had to do this because we use IEavAttribute extensively and need access to the properties in Entity (IEntity).

Here is a simplified view of the model:

public interface IEntity {
    Int32 Id { get; }
    ...
}

public abstract Entity : IEntity {
    public virtual Int32 Id { get; protected set; }
    ...
}

public interface IEavAttribute : IEntity {
    String Name { get; set; }
    Object Value { get; set; }
    ...
}

public EavAttribute<T> : Entity, IEavAttribute {
    private T _value;

    public virtual String Name { get; set; }
    ...
}

public class IEavAttributeMap : ClassMap<IEavAttribute> {
    public IEavAttributeMap() {
        Table("Attributes");

        Id(x => x.Id)
            .Column("AttributeId");

        HasMany<IEavAttribute>(x => x.Attributes)
            .KeyColumn("AttributeId")
            .AsMap<String>("Name")
            .Inverse()
            .Cascade.AllDeleteOrphan();
    }
}

public class EavStringAttributeMap : SubclassMap<EavAttribute<String>> {
    public EavStringAttributeMap() {
        Table("StringAttributes");

        KeyColumn("StringAttributeId");

        Map(x => x.Value)
            .Access
                .CamelCaseField(Prefix.Underscore)
            .Column("AttributeValue")
                .CustomType(typeof(System.String))
            .Nullable();
        }
    }

The mapping files that get generated (using ExportTo()) actually look right, but when I try to generate the schema using SchemaExport, I get an error saying "could not find a setter for property Id in class IEavAttribute."

That makes sense because IEntity doesn't have a setter defined for Id. I've tried looking into the Extends method in the EavStringAttributeMap class but couldn't figure it out.

How might I use FNH to tell NH how to set that Id property on the abstract class inherited by EavAttribute<T>?

  1. 2 Posted by Devon Lazarus on 09 Jun, 2010 05:14 PM

    Devon Lazarus's Avatar

    Marking the discussion resolved as I have gone back to hand-mapping to address my needs.

Comments are currently closed for this discussion. You can start a new one.