SmoothNHibernateExceptionMovingObjectsBetweenCollections将对象从一个集合移动到另一个集合时,当cascade设置为all-delete-orphan时,出现如下异常:Deletedobjectswill通过级联重新保存(删除的对象从关联中删除)我认为当您使用all-delete-orphan时,nhibernate在另一个集合中引用它时不会删除它。当您拥有包含文件夹或文件的文件夹之类的对象并将文件从一个文件夹移动到另一个文件夹时,任何人都可以确认您不应该得到这个异常吗?我在vs2010中制作了一个示例项目来演示这种行为。谁能说我的映射是正确的还是nhibernate中有错误?FileMapping.cspublicclassFileMapping:ClassMap{publicFileMapping(){Id(x=>x.Id,"Id").GeneratedBy.Native("File_seq");Map(x=>x.Name,"Name").Not.Nullable();引用(x=>x.Folder).Not.Nullable().Column("idFolder");}}FolderMapping.cspublicclassFolderMapping:ClassMap{publicFolderMapping(){Id(x=>x.Id,"Id").GeneratedBy.Native("Folder_seq");Map(x=>x.Name,"Name").Not.Nullable();HasMany(x=>x.Folders).Inverse().Cascade.AllDeleteOrphan().KeyColumn("idParentFolder");HasMany(x=>x.Files).Inverse().Cascade.AllDeleteOrphan().KeyColumn("idFolder");References(x=>x.ParentFolder).Nullable().Column("idParentFolder");}}示例项目:http://www.mediafire.com/?orxcw63aziq54xoExplanation:MakesuretheconnectionstringinProject'spropertiesiscorrectRuntheproject单击第一个按钮:连接到数据库单击右上角的按钮Createtablesandsampledata(2folderobjectsand1file)单击Buttonsmovefileobjectstoother文件夹对象单击按钮保留机会是:您将得到一个DeletedObjectExceptionNHibernate有一个非常本地化的孤儿视图。如果将对象从文件夹A移动到文件夹B,文件夹A会将其视为孤立对象,因此将其删除。文件夹B要更新一个对象,发生冲突。这叫做重新养育,你在这里读到它http://fabiomaulo.blogspot.com/2009/09/nhibernate-tree-re-parenting.html基本上,它是你收藏中孤儿的重新养育意义选项,所以您的对象不会被删除。以上就是C#学习教程:smoothNHibernateexceptionmovesobjectsbetweencollections,共享所有内容。如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注。本文来自网络收藏,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
