开发者

Lazy loading is not working for one to many

开发者 https://www.devze.com 2022-12-30 21:57 出处:网络
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 co

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()
  开发者_StackOverflow          .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


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'");


Upgrading to version 3.0 solved the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号