Entity Framework Will Not Preserve Relationships

I have the following situation:

role.Permissions.Add(permission);
objectContext.SaveChanges();

When I look at the Roles_Permissions relationship table now, there is no new added permission for the role. It only retains a new relationship when I have the context of the object. Am I doing something wrong or does the SaveChanges call not save the changes in the relationship sets?

+3
source share
4 answers

ObjectStateManager - SaveChanges, , , - , . , - . SaveChanges .

+1

, .

, .

, .

0

, . .

0

You can verify that your permission object is known to your object by running the following line of code:

objectContext.AddObject("Permissions", permission);
0
source

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


All Articles