views:

163

answers:

0

Hi,

I am having a problem in that the objects that I am using to map to nhibernate all implement an interface and on each interface any relationships with other objects are defined as an interface property. So given the following interface,

public interface ISettingValue
{
    int RoleId { get; }

    ISetting Setting { get; }

    string Value { get; }
}

Because my relationship with setting is declared as ISetting in my interface, so must the relationship on my concrete object.

public class SettingValue : ISettingValue
{
    public int RoleId { get; set; }

    public ISetting Setting { get; set; }

    public string Value { get; set; }
}

What I'm trying to achieve is to create a Composite Primary Key our of the RoleId property and the Id field of the Setting object.

So although I can map the ISetting property's relationship just fine like so,

        References<Setting>(x => x.Setting);

When I try to map this by either,

        CompositeId().KeyProperty(x => x.RoleId)
                     .KeyReference(x => x.Setting.Id);

Or,

        CompositeId().KeyProperty(x => x.RoleId)
                     .KeyReference(x => x.Setting);

I get an exception,

An association from the table SettingValue refers to an unmapped class: ISetting

Which I guess makes sense given that nHibernate won't have known what to do with ISetting.

My question is, is there a way to declare this mapping and specify a type mapping from ISetting to Setting just like what is done when declaring the object relationship with the code,

         References<Setting>(x => x.Setting);

Any help will be must appreciated. Thanks.