I have a db with some tables that I need to map:

Table_S (with field ids as pk)
Table_P (with field idp as pk)
Table_C (with field idc as pk)
Table_SC (with fields ids,idc as pk) where this table define a many to many 
relation between Table_S and Table_C
Table_SCP (with fields ids,idc,idp as pk) where this table define a many to 
many relation between Table_SC and Table_P

I want to design my object graph as show under:

Class_S
        |---Bag of Class_SC (owner is class_s)
                        |---Bag of Class_SCP (owner is class_sc)

My model works only partially, because any instance of Class_SC has always an 
empty collection of Class_SCP (any instane of class_S, instead, load always a 
his collection of Class_SC)

The mapping that I have implemented is for class_s, class_sc and class_scp is 
(here omit for brevity mapping for Class_P and Class_C)

class Class_SMap
        : ClassMapping<Class_S>
        {
        public Class_SMap() {
            Table("table_s");

            Id(...);
                
            Bag(..., cm => {
                cm.Inverse(true);
                cm.Access(Accessor.NoSetter);
                cm.Lazy(CollectionLazy.Lazy);
                cm.Key(key => {
                    key.Column("ids");
                    key.NotNullable(true);
                    key.OnDelete(OnDeleteAction.Cascade);
                });
                cm.Cascade(Cascade.All | Cascade.DeleteOrphans);
            }, m =>
            {
                m.OneToMany(om => {
                    om.Class(typeof(ClassSC));
                    om.NotFound(NotFoundMode.Ignore);
                });
            });
        }
    }


class Class_SCMap
        : ClassMapping<Class_SC>
    {
        public Class_SCMap() {
            Table("table_sc");

            ComponentAsId(x => x.Id, pk => {
                ...
            });
ManyToOne<Class_S>(..., m => {
                m.Column("ids");
                m.Update(false);
                m.Insert(false);
                m.NotFound(NotFoundMode.Ignore);
                m.Cascade(Cascade.None); //unit-test
            });
            ManyToOne<Class_C>(..., m=> {
                m.Column("idc");
                m.Update(false);
                m.Insert(false);
                m.NotFound(NotFoundMode.Ignore);
                m.Cascade(Cascade.None);//unit-test
            });
                'Not works
            Bag(..., cm => {
                cm.Inverse(true);
                cm.Access(Accessor.NoSetter);
                cm.Lazy(CollectionLazy.Lazy);
                cm.Key(key => {
                    key.Columns(m => m.Name("ids"), m => m.Name("idc"));
                    key.NotNullable(true);
                    key.OnDelete(OnDeleteAction.Cascade);
                });
                cm.Cascade(Cascade.All | Cascade.DeleteOrphans);
            }, m =>
            {
                m.OneToMany(om => {
                    om.Class(typeof(Class_SCP));
                    om.NotFound(NotFoundMode.Ignore); });
            });
        }
    }

class Class_SCPMap
        : ClassMapping<Class_SCP>
    {
        public Class_SCPMap() {
            Table("table_scp");

            ComponentAsId(...);

            ManyToOne<Class_S>(..., m => {
                m.Column("ids");
                m.Update(false);
                m.Insert(false);
                m.NotFound(NotFoundMode.Ignore);
                m.Cascade(Cascade.None); //unit-test
            });
            ManyToOne<Class_C>(..., m=> {
                m.Column("idc");
                m.Update(false);
                m.Insert(false);
                m.NotFound(NotFoundMode.Ignore);
                m.Cascade(Cascade.None);//unit-test
            });
            ManyToOne<Class_P>(..., m => {
                m.Column("idp");
                m.Update(false);
                m.Insert(false);
                m.NotFound(NotFoundMode.Ignore);
                m.Cascade(Cascade.None); //unit-test
            });

}
    }

Anyone can help me to discovere the my mistake?

--
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to