English 中文(简体)
如何删除使用FluentNHibernate的参考物体(即旧的“被删除的物体将用cade机销毁”)
原标题:How to delete a referenced object using FluentNHibernate (ye olde "deleted object would be resaved by cascade")

我的错误是司空见惯的,但我没有找到任何回答我的情况:

实体:

School Teacher Student

绘图:

School:  mapping.HasMany(x => x.Students).Cascade.AllDeleteOrphan();
Student: 
      mapping.References(x => x.Teacher).Not.Nullable().Cascade.SaveUpdate();
      mapping.References(x => x.School).Not.Nullable().Cascade.SaveUpdate();
Teacher: 
      mapping.References(x => x.School).Not.Nullable().Cascade.SaveUpdate();
      mapping.HasMany(x => x.Students).Cascade.All().Inverse();

假设:学生与没有其他学生或教师的学校有联系。 如果我想将学生与另一所学校联系起来,我就要删除孤儿学校。

if (oldSchool.Students.Count == 1 && oldSchool.Teachers.Count == 0)
{
    //delete it
    //oldSchool.Students.Remove(student);
    student.School = null;

    _schoolRepository.Delete(oldSchool);
}

这里发生的情况是,当我拯救“智者”时,我获得的“被删除的物体将因“cade”错误而消失。

一如既往,任何帮助都受到高度赞赏。

问题回答

你们的其余情况一样? 学校与学生之间的不利环境是什么?

Try mapping.HasMany(x =>x.Students).Cascade.AllDeleteOrphan(). 原文:





相关问题
Does Fluent NHibernate support "trigger-identity"

I posted the question in the Fluent-NHibernate newgroup but so far there has been no answer from the void. Is there a Fluent NHibernate mapping for the NHibernate "trigger-identity" method of ...

automapping nested components naming conventions

Im making the switch from Fluent Mapping to Automapping in my current project. If I have the following domain: public class Matter{ public Client Client{get;set;} } public class Client { ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

Fluent nHibernate keeps recreating my database, why?

I m trying to convert my data layer from Linq2Sql to nHibernate. I think Xml the configuration in nHibernate is pretty backwards so I m using Fluent. I ve managed to get fluent, add in a repository ...

How to fluent-map this (using fluent nhibernate)?

I have two tables in my database "Styles" and "BannedStyles". They have a reference via the ItemNo. Now styles can be banned per store. So if style x is banned at store Y then its very possible that ...

热门标签