PersistanceSpecification CheckList 在多对多关系上失败
我遇到的问题是我的单元测试有时会通过,有时会失败。我的单元测试使用 PersistanceSpecification 类来测试两个实体之间的多对多关系。看来我遇到了与此处描述的问题完全相同的问题:
有其他人遇到过这个问题吗?如果是的话,您是否能够在不放弃 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上是
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