Loose NHibernate HasMany in component

Below is the Oracle class model and schema that I would like to map using Fluent NHibernate.

public enum EnumA { Type1, Type2, Type3 };
public class ClassB
{
    public virtual string Property1 { get; set; }
    public virtual string Property2 { get; set; }
}

public class ClassA
{
    public virtual int ID { get; set; }
    public virtual string Name { get; set; }
    public virtual IDictionary<EnumA, IList<ClassB>> MyDictionary { get; set; }
}

      

Table A (NUMBER (38) ID PK, VARCHAR2 (255) Name)
TableB (NUMBER (38) ID PK FK, NUMBER (38) Type PK, VARCHAR (255) Prop1, VARCHAR (255) Prop2)

How to define a Fluent NHibernate mapping class?
I don't mind introducing a new domain class if needed. I've tried the following:

public class ClassB
{
    public virtual string Property1 { get; set; }
    public virtual string Property2 { get; set; }
}

public class classC
{
    public virtual EnumA EnumA { get; set; }
    IList<ClassB> ClassBList { get; set; }
}

public class ClassA
{
    public virtual int ID { get; set; }
    public virtual string Name { get; set; }
    public virtual IDictionary<EnumA, classC> MyDictionary { get; set; }
}

      

with the following display class

    public ClassAMap()
    {
        WithTable("ClassA");
        Id(x => x.ID);
        Map(x => x.Name);

        HasMany(x => x.MyDictionary).AsMap<EnumA>(d => d.EnumA).Component(c =>
        {
            c.HasMany(e => e.ClassBList).Component(f =>
                {
                    f.Map(x => x.Property1);
                    f.Map(x => x.Property1);
                });
        });
    }

      

However, this does not create the correct configuration. Can anyone please help?

+1


a source to share


1 answer


Class B is not a component of A, it is a related object with its own identity (id, type), so it cannot logically be a component, since components do not have their own identity (PK), otherwise they will be separate objects.



0


a source







All Articles