views:

48

answers:

1

Any 1-M that use the primary key of the parent table, but any 1-M that uses a different column does not work. It generates the SQL correctly, but put the value of the key into the SQL instead of the column value I want.

Example mapping:

    public TemplateMap()
    {
        Table("IMPORT");

        LazyLoad();

        Id(x => x.ImportId).Column("IMPORT_ID").GeneratedBy.Assigned();

        Map(x => x.ImportSetId).Column("IMPORTSET_ID");

        HasMany(x => x.GoodChildren)
            .Access.CamelCaseField()
            .KeyColumns.Add("IMPORT_ID")
            .Cascade.Delete()
            .Inverse();

        HasMany(x => x.BadChildren)
            .Access.CamelCaseField()
            .KeyColumns.Add("IMPORTSET_ID")
            .Cascade.Delete()
            .Inverse();
    }

Lazy loading works for GoodChildren, but not for BadChildren.

The SQL statement is correct for both children. But the wrong values are use. If the value of IMPORT_ID is 10 and the value of IMPORTSET_ID is 12. The value 10 will be used for the IMPORTSET_ID in the SQL for BadChildren instead of 12.

Anyone have any ideas what I need to change to get BadChildren to work correctly?

Note:
GoodChildren links to IMPORT_ID on Template

BadChildren links to IMPORTSET_ID on Template

A: 

I'm not sure how to do it the way you want do it, but an alternative is to use a column on your children table to identify what kind of child the record is:

        HasMany(x => x.GoodChildren)
            .Table("tblChildren")
            .Where("CHILD_TYPE='Good'");

        HasMany(x => x.BadChildren)
            .Table("tblChildren")
            .Where("CHILD_TYPE='Bad'");
taoufik
The GoodChildren table is workign fine, because its composite key includes the parent identity column (i.e. primary key). The badColumn table is not workign because its composite key include a column that is not the parent identify column. Additional, they are TWO DIFFERENT tables, not the same table. I changed the names to try and make it more obvious. If it matters one is called fields and the other archive.
Shire