开发者

Self-Referential List Index [NH 3.2]

I have a self-referential relationship in an entity and for the life of me can't figure this out.

I have a type, "Project" which has a number of properties on it which for this case don't matter, but the interesting part is the following:

ca.ManyToOne(x => x.Parent, map =>
{
    map.Class(typeof(Project));
    map.Column("ParentProjectID");
});

ca.List(x => x.Children, map =>
{
    map.Key(k => k.Column("ParentProjectID"));
    map.Index(i =>
    {
        i.Column(x =>
        {
            x.Default(1);
            x.Name("Position");
        });
    });
    map.Inverse(true);
    map.Lazy(CollectionLazy.NoLazy);
    map.Cascade(Cascade.All | Cascade.DeleteOrphans);
},
e => e.OneToMany(x => x.Class(typeof(Project))));

The problem I'm having is that when开发者_如何学C I create my projects and sub-projects the "Position" field isn't set in the DB, it's just left as "1" or "null" depending on the option I set. For type list you need a populated index field if there's more than one otherwise you'll get an exception of type ListDictionaryInternal with the message of "null index column for collection" for the name of your collection.

The project is created in the DB by an importer, and the index should be auto-generated based on the mapping/NH configuration.

Has anyone got any experience in this area? I simply want it to auto-populate the index, otherwise just listing the child items won't work.


This was actually a major bug in NH 3.2.2000 however the GC was NH 3.2.4000 which seemed to (mostly) address it. We don't have time to produce a test project to submit as an example to show the bug. Incorrect SQL statements were being issued, so the answer is to do Session.Flush() inbetween some statements, especially when it comes to self-referential lists.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜