Maping details collection using interface for detail

Alexander Kot's Avatar

Alexander Kot

26 Nov, 2010 01:24 PM via web

Hello
I am playing with NH + FNH 2.0.0.697 now and can define

IDictionary<string, TestEntityDetail2> Details2 { get;  }

details for master entity where detail is concrete class.
but cannot

IDictionary<string, ITestEntityDetail2> Details2 { get;  }

where details defined as interface

Next code works fine

public interface ITestEntityDetail2
{
    bool Flag { get; set;}
}
public class TestEntityDetail2 : ITestEntityDetail2
{
    public virtual bool Flag { get; set; }
}
public interface ITestEntity : .....
{
    IDictionary<string, TestEntityDetail2> Details2 { get;  }   //!! TestEntityDetail2 there not ITestEntityDetail2
}
public class TestEntity : Entity<Guid>, ITestEntity
{
    public virtual IDictionary<string, TestEntityDetail2> Details2 { get; protected set; }
}
public class TestEntityMap : ClassMap<TestEntity>
{
    public TestEntityMap()
    {
         //......
         HasMany(x => x.Details2).Table("TABLEX").ForeignKey("FK_COL")
            .DictionaryKey("KEY_COL").Component(
                    c => c.Map(.......).Column("......")
                );
    }
}

But if change TestEntityDetail2 to ITestEntityDetail2 in ITestEntity interface - I cannot define working mapping
It seems to me that it must be some construction like
1) HasMany(x => x.Details2).Table("TABLE").ForeignKey("FK_COL")

            .DictionaryKey("KEY_COL").Component<TestEntityDetail2>(
                    c => c.Map(.......).Column("......")
                );

It doesn't compiles now or
2) HasMany(x => x.Details2).Table("TABLE").ForeignKey("FK_COL")

            .DictionaryKey("KEY_COL").DictionaryValue<TestEntityDetail2>().Component<TestEntityDetail2>(
                    c => c.Map(.......).Column("......")
                );

It compiles but doesn't help

Any ideas how to define such mapping?

    Reply to this discussion

    Preview Comments are parsed with Markdown. Help with syntax

    Attached Files

      You can attach files up to 10MB

      Five times two is what?