【问题标题】:Fluent NHibernate - Cascade delete a child object when no explicit parent->child relationship exists in the modelFluent NHibernate - 当模型中不存在显式父->子关系时级联删除子对象
【发布时间】:2010-04-23 03:54:45
【问题描述】:

我有一个应用程序可以跟踪(为了举例)在给定餐厅有哪些饮品。我的域模型如下所示:

class Restaurant {
    public IEnumerable<RestaurantDrink> GetRestaurantDrinks() { ... }
    //other various properties
}

class RestaurantDrink {
    public Restaurant Restaurant { get; set; }
    public Drink { get; set; }
    public string DrinkVariety { get; set; }  //"fountain drink", "bottled", etc.
    //other various properties
}

class Drink {
    public string Name { get; set; }
    public string Manufacturer { get; set; }
    //other various properties
}

我的数据库架构(我希望)是您所期望的; “RestaurantDrinks”本质上是餐厅和饮料之间的映射表,带有一些额外的属性(例如添加了“DrinkVariety”)。

使用 Fluent NHibernate 设置映射,我设置了从餐厅到 RestaurantDrinks 的“HasMany”关系,这会导致后者在其父餐厅被删除时被删除。

我的问题是,鉴于“Drink”没有任何明确引用 RestaurantDrinks 的属性(该关系仅存在于底层数据库中),我是否可以设置一个映射,如果关联的 RestaurantDrinks 将导致删除饮料被删除了?

更新:我一直在尝试使用“RestaurantDrink”设置映射

References(x => x.Drink)
    .Column("DrinkId")
    .Cascade.All();

但这似乎不起作用(删除饮料时我仍然会违反 FK)。

【问题讨论】:

    标签: c# fluent-nhibernate nhibernate-mapping


    【解决方案1】:

    这个问题的答案表明我想做的事情是不可能的:how to define an inverse cascade delete on a many-to-one mapping in hibernate

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-15
      相关资源
      最近更新 更多