- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个数据库,其中包含一个 ProbateCases 表和一个 Properties 表。 ProbateCases 表有一个名为 ProbateCaseId 的 ProbateCases 表的外键,因此 ProbateCases 和 Properties 之间的关系是一对多的。
我的域层有一个 ProbateCase 类和一个 Property 类。 ProbateCase 类具有一组定义如下的属性:
private IList<Property> _properties = new List<Property>();
public virtual IEnumerable<Property> Properties { get { return _properties; } }
public virtual Property AddProperty()
{
Property property = new Property();
_properties.Add(property);
return property;
}
Fluent NHibernate 映射的相应部分如下所示:
HasMany(x => x.Properties).Where("Deleted = 0").KeyColumn("ProbateCaseId").Cascade.All().Access.CamelCaseField(Prefix.Underscore);
请注意关联是单向的——ProbateCase 类有一个 Properties 集合,但 Property 类没有 ProbateCase 成员。
我发现查询工作正常 - NHibernate 正在创建适当的 SQL 以获取具有适当 ProbateCaseId 值的属性。
但是,当我保存一个添加了新属性的 ProbateCase 时,INSERT SQL 不包含外键字段的值 - 所以我得到一个 SQL 异常,提示外键中的 NULL 值:
INSERT INTO AdminOverview.Properties (PropertyName) VALUES ('Name of property') -- Where the hell is the ProbateCaseId field value???
我应该期待 NHibernate 自己填充外键值,还是我应该做其他事情?
最佳答案
来自 http://nhibernate.info/doc/nh/en/index.html#collections-onetomany :
Very Important Note: If the column of a association is declared NOT NULL, NHibernate may cause constraint violations when it creates or updates the association. To prevent this problem, you must use a bidirectional association with the many valued end (the set or bag) marked as inverse="true". See the discussion of bidirectional associations later in this chapter.
关于nhibernate - 流利的 NHibernate : foreign key field not being set in unidirectional association,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4302560/
我正在尝试将fluentd与elasticsearch连接起来,并且在启动td-agent服务时遇到此错误。 td-agent.log: 无法与Elasticsearch通信,重置连接并重试。连接被拒
所以我有一个案例,布局已经变得更加复杂。有一些常见的东西,比如 @section styleIncludes{ ... } ,然后是其他部分,这些部分定义了每个页面可以选择(但几乎总是)指定的各种内容
我刚刚看到一个巨大的 Java 正则表达式,它让我对一般正则表达式的可维护性有所思考。我相信大多数人——除了一些糟糕的 perl 贩子——都会同意正则表达式很难维护。 我在考虑如何解决这种情况。到目前
我有一个 12 秒长的 audio.mp3 文件video.mp4 的长度为 60 秒。 我需要在视频的第 40 秒插入audio.mp3。 如何使用 Node-Fluent-ffmpeg 做到这一点
我正在使用 NHibernate + Fluent 来处理我的应用程序中的数据库。到目前为止,我一直在使用 SessionSource 来创建我的 ISession 对象。我现在对来自 NHibern
我在 Java 控制台应用程序中使用 Apache HttpClient 4.5(具有流畅的界面)。我注意到,它的默认超时值似乎是无限的,但我必须为我发送的请求使用非无限的超时值。我想对所有请求使用相
这是我的路线: router.get("answers","delete", Int.parameter) { req -> Future in let answerID = try
我有随机“ session 已关闭!” Autofac 和 Fluent nHibernate 的以下配置错误: 全局.asax.cs: builder.Register(x => new NHibe
我是一名优秀的程序员,十分优秀!