In the Entity Framework, how to specify a condition for an association?

I have a relational model with an associative table. But in addition to the associated keys, this table also has a flag. I would like to define two associations: one where the flag is true and the other where it is false. An EF designer can add a condition to an entity, but not to an association.

The associative table looks like this:

UserPrivilege
-------------
UserId int (FK1)
PrivilegeId int (FK2)
IsGranted bit

I would like to create two associations between the User object and Entivity: PrivilegesGranted and PrivilegesDenied.

+3
source share
1 answer

You cannot do this directly through the constructor.

XML, DefiningQuery Create and Delete sprocs. : .

, , , PK - UserId PrivilegeId, , .

, :

Privilege p = user.Granted.First();
user.Granted.Remove(p);
user.Denied.Add(p);
ctx.SaveChanges();

. DefiningQuery , EF , , , .

, .

sprocs , "" "", , IsGranted, , .. .

, .

+2

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


All Articles