Lets assume I have and entity called Debt
:
public class Debt
{
[Key]
public int Id { get; set; }
public int Amount { get; set; }
public int UserId { get; set; }
}
I'm using Code first, so I just simply introduce IDbSet<Debt>
and use it.
After that I want to add some security for read on DB level: I've created a view called Debt_Read:
CREATE VIEW Debt_Read AS SELECT * FROM Debt WHERE UserId IN (1,2,3)
Let's keep view body simple, in real life this code use some sql function for retrieving user id from session.
I wan't EF to map my DbSet<Debt>
to read from VIEW and to write update and create to TABLE.
How can I achieve this?