Fluent NHibernate - Cascade removes a child if the model does not have explicit parent> child relationships

I have an application that tracks (for example) which drinks are available in this restaurant. My domain model looks like this:

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
}

My db scheme (I hope) about what you expect; RestaurantDrinks is essentially a comparison table between restaurants and drinks with some additional features (like DrinkVariety).

Using Fluent NHibernate to set up the mappings, I connected "HasMany" to restaurants in RestaurantDrinks, which forces the latter to be deleted when its parent restaurant is deleted.

, "Drink" , RestaurantDrinks ( ), , RestaurantDrinks, ?

: "RestaurantDrink",

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

( FK ).

+3
1

, , , : "--"

+3

Source: https://habr.com/ru/post/1742390/


All Articles