栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

无法删除集合:[NHibernate.Exceptions.GenericADOException]

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

无法删除集合:[NHibernate.Exceptions.GenericADOException]

只有两种方法可以解决此问题。

1)不要使用

inverse="false"

<bag name="tableB" lazy="true" inverse="true" // instead of false         batch-size="25" cascade="all-delete-orphan">  <key column="tabAId" />  <one-to-many  /></bag>

此设置 (inverse =“ true”) 将指示NHibernate直接从数据库中删除 项目

虽然使用

inverse="false"
will通常会导致:

  • UPDATE(带null)==从集合中删除
  • 删除项目==级联行为

2)使引用列可为空

这意味着,我们可以让NHibernate进行UPDATE和DELETE。因为column现在可以为空。

这些只是这里解决问题的两种方法。

我的偏好是: inverse =“ true”

为了正常工作,

inverse="true"
我们总是必须在C#中分配关系的两端。这对于Add(),INSERT操作是必须的:

Parent parent = new Parent();Child child = new Child{    ...    Parent = parent,};// unless initialized in the Parent type, we can do it hereparent.Children = parent.Children ?? new List<Child>();parent.Children.Add(child);// now just parent could be saved// and NHibernate will do all the cascade as expected// and because of inverse mapping - the most effective waysession.Save(parent);

如我们所见,我们 已经 明确 指定
了关系的双方。必须从NHibernate逆映射中获利。这也是一个好习惯,因为稍后,当我们期望从数据库加载数据时,NHibernate将为我们设置该设置



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/382907.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号