Suppose I have an entity called Debt:
public class Debt
{
[Key]
public int Id { get; set; }
public int Amount { get; set; }
public int UserId { get; set; }
}
I use Code first, so I just imagine IDbSet<Debt>and use it.
After that, I want to add some security for reading at the database level: I created a view called Debt_Read:
CREATE VIEW Debt_Read AS SELECT * FROM Debt WHERE UserId IN (1,2,3)
Although the body remains simple, in real life this code uses some sql function to retrieve the user ID from the session.
I do not want EF to display mine DbSet<Debt>for reading from VIEW and for writing updates and creating in TABLE.
How can i achieve this?
source
share