开发者

PersistanceSpecification CheckList fails on Many-to-Many relationship

I'm having an issue where my unit test passes sometimes and fails sometimes. My unit test uses the PersistanceSpecification class to test a ManyToMany relationship between two of my entities. It seems like I'm running into the exact same issue as the one described here:

http://fluentnhibernate.lighthouseapp.com/projects/33236/tickets/170-persistencespecification-checklist-fails-on-many-to-many-relationship

Has anyone else ran into this and if so were you able solve it or work around it without abandoning PersistanceSpecification?

I think this all started happening when I exposed my collections as IEnumerable with private backing fields instead of g开发者_StackOverflowiving the property direct access to the underlying collection.

Here is an example of my entities and their mappings:

public class UserHeaderMap : ClassMap<UserHeader>
{
    public UserHeaderMap()
    {
        Id(x => x.UserId);

        HasManyToMany(x => x.Groups)
            .Table("USER_GROUP_COMPOSITE")
            .ParentKeyColumn("USER_ID")
            .ChildKeyColumn("GROUP_ID")
            .Access.CamelCaseField()
            .Cascade.All()
            .Inverse()
            .FetchType.Join();
    }
}

public class GroupHeaderMap : ClassMap<GroupHeader>
{
    public GroupHeaderMap()
    {
        Id(x => x.GroupId);

        HasManyToMany(x => x.Users)
            .Table("USER_GROUP_COMPOSITE")
            .ParentKeyColumn("GROUP_ID")
            .ChildKeyColumn("USER_ID")
            .Access.CamelCaseField();
    }
}

//Unit test runs the following (some things are omitted for brevity)
new PersistenceSpecification<UserHeader>(session)
                    .CheckList(x => x.Groups, groups, (x, g) => x.AddGroup(g))
                    .VerifyTheMappings();


This is actually a bug within the PersistanceSpecification class and is tracked as such in Fluent NH.

The bug is being tracker here: https://github.com/jagregory/fluent-nhibernate/issues/59

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜