本文介绍了无法删除集合:[NHibernate.Exceptions.GenericADOException]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有两个表,表A和tableB的 表A有列:tabAId,COL2,COL3 (tabAId的PrimaryKey和标识列)。 tableB的有柱:tabAId,名称(tabAId不为null) 我在表A的HBM文件中创建袋,以保持关系船 <包名称=tableB的懒= 真正的逆=false的批量大小=25级联=全删除,孤儿> <键列=tabAId/> 将;一对许多类=tableB的/> < /袋> 当我尝试更新记录的表A 扔例外,如我在表A的实例孩子的名单。 解决方案 There are only two ways how to solve this.1) do not use 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 class="tableB" /></bag>This setting (inverse="true") will instruct NHibernate to directly delete an item from DB.While using inverse="false" will in general always lead to:UPDATE (with null) == act of removing from collectionDELETE item == act of cascade2) make the reference column nullableThat means, that we can leave NHibernate to do UPDATE and DELETE. Because column is now nullable.These are only two ways how to solve it here.My preference would be: inverse="true"To work properly with inverse="true" we always have to assign both sides of relation in C#. This is a must for Add(), INSERT operation: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);As we can see, we have assigned - explicitly - both sides of relationship. This is must to profit from NHibernate inverse mapping. And it is also good practice, because later, when we load data from DB we expect, that NHibernate will take care about setting that for us 这篇关于无法删除集合:[NHibernate.Exceptions.GenericADOException]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!