I have problem I cannot find a solution for: basically I would like how to turn off cascading update on a EF CodeFirst many to many association.
I have two classes List and Recipient.
public class List
{
public string DisplayName { get; set; }
public DateTime? LastSyncronized { get; set; }
public virtual ICollection<Recipient> Recipients { get; set; }
}
public class Recipient
{
public int Id { get; set; }
public String Name { get; set; }
public virtual ICollection<List> Subscriptions { get; set; }
}
During some processing I need to add to the Recipients property of a List a number of Recipient that I take from an external source.
Then I do my processing and at the end I have to same the List to update the LastSyncronized property.
Unfortunately, when I save, the automatic tracking of EF also saves into the database all the Recipients I’ve taken from the external source.
How can I configure the DbContext not to persist the new objects to the Database?
I tried removing them all from the collection, but even that they are added to the database anyway. In this case, the join table is unchanged, but the recipient one is added with the new recipients.
Thank you
Simone
Not sure this is the right solution to this, but I set, in the DbContext class:
Now object added are not added to the database.