The problem is following: I have three related tables, one storing Clients info, second storing SubscriptionTypes and third Payment.

When Payment is created, consisting of ClientId and SubscriptionId, client with proper Id is updated with proper subscription.

The issue which I cant handle is when I delete Client, also all payments associated with this client are deleted. I suspect it may be related to CascadeDeleting, although cannot really find how to solve that one.

This are my models:

public class Payment
{
    [Key]
    public int Id { get; set; }

    public int ClientId { get; set; }
    public Client Client { get; set; }

    public int SubscriptionId { get; set; }
    public Subscription Subscription { get; set; }

    // More properties...     
}

public class Client    
{
    [Key]
    public int Id { get; set; }        

    public int? SubscriptionId { get; set; }
    public Subscription Subscription { get; set; }

    // More properties...
}

public class Subscription
{
    [Key]
    public int Id { get; set; }

    // etc.
}

1 Answers

0
maroine chérif On Best Solutions

From the column_constraint page on MSDN:

ON DELETE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } Specifies what action happens to rows in the table that is altered, if those rows have a referential relationship and the referenced row is deleted from the parent table. The default is NO ACTION.