user706058
user706058

Reputation: 415

Linq to Entities: .Clear() does not delete relation row, only relation column value

I have a 'users' and 'notifications' tables. The tables definition are:

users        notifications
-------      -------------
ID (PK)      ID (PK)
Name         Name
             users_ID (FK / Relation)

When I do:

MyUserEntity.notifications.clear();
MyContext.SaveChanges();

The users_ID column value(s) for the corresponding user entity are set to NULL, but I want the rows to be deleted.

What am I missing? Thanks!

Upvotes: 0

Views: 391

Answers (1)

Bala R
Bala R

Reputation: 109027

Try

foreach(var notification in MyUserEntity.notifications.ToList())
{
    MyContext.DeleteObject(notification);
}
MyContext.SaveChanges();

Upvotes: 1

Related Questions