Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello dears,

I have a situation as follows:
I want to alter all get queries in my application to skip deleted records which is marked as deleted in DB.

Can i configure the context to exclude to do that instead of altering all queries?

Regards,
Amr

What I have tried:

i have searched a lot but i didn't get any result.
I 've also tried to edit all get queries but this will take a lot of time.
Posted
Updated 22-Apr-18 22:51pm
Comments
F-ES Sitecore 23-Apr-18 4:44am    
There might be something clever with EF that can do this, but generally these kind of things are handled by using a repository pattern which allows you to have a single point of code where a "get" is done (and other functions can use that function as a basis of their own queries) so filtering out deleted records is just a case of changing one method. However if your code is not using a repo pattern it's going to involve a lot of refactoring.
_ProgProg_ 23-Apr-18 4:46am    
Yes but unfortunately i am not using repository pattern.
Richard Deeming 24-Apr-18 9:39am    
How much control do you have over your database, or your EF mapping?

You could simply create views in the database corresponding to each table, which filter out the soft-deleted records. You could then map your EF sets to the views instead of the underlying tables.
_ProgProg_ 24-Apr-18 9:41am    
can you give me a detailed example?

1 solution

Quote:
Can i configure the context to exclude to do that instead of altering all queries?

No, you have to alter your queries.

For further details, please see:
Entity Framework Working with DbContext[^]
Entity Framework Querying and Finding Entities[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900