How instruct EF to don't delete OneToMany relations but cascade delete collections?
i.e.:
public class Client
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Order
{
public int Id { get; set; }
public int ClientId { get; set; }
[ForeignKey("ClientId")]
public Client Client { get; set; }
public ICollection<OrderItem> OrderItems { get; set; }
}
public class OrderItem
{
public int Id { get; set; }
public int OrderId { get; set; }
[ForeignKey("OrderId")]
public Order Order { get; set; }
}
In this model, when I try to delete a Client associated with some Orders I would like to avoid the deletion (1). However when I try to delete a Order with some OrderItems I would like to remove the Order and the associeted OrderItems (2).
I also have one limitation about the FK column: it's in [Model]Id format instead the EF default [Model]_Id form.
If I define
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
the (1) works fine but (2) trigger an error.
There's an alternative except using Fluent for each collection? How do to this in Fluent anyway?