PersistanceSpecification CheckList 在多对多关系上失败

发布于 2024-11-03 18:06:53 字数 1611 浏览 1 评论 0原文

我遇到的问题是我的单元测试有时会通过,有时会失败。我的单元测试使用 PersistanceSpecification 类来测试两个实体之间的多对多关系。看来我遇到了与此处描述的问题完全相同的问题:

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

有其他人遇到过这个问题吗?如果是的话,您是否能够在不放弃 PersistanceSpecification 的情况下解决或解决它?

我认为这一切都是在我将集合公开为带有私有支持字段的 IEnumerable 时开始发生的,而不是让属性直接访问底层集合。

这是我的实体及其映射的示例:

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();

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 giving 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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不美如何 2024-11-10 18:06:53

这实际上是 PersistanceSpecification 类中的一个错误,并在 Fluent NH 中进行跟踪。

该错误正在此处进行跟踪:
https://github.com/jagregory/ Fluent-nhibernate/issues/59

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文