C
C#7mo ago
Core

✅ EF: how to structure same EF select query with no tracking?

Hello, I need the exact same select query with and without tracking. Should I implement it in 2 separate methods or a single method with a bool parameter that would determine if the query will use tracking or not (e.g. SelectSomething(enableTracking = true))?
9 Replies
this_is_pain
this_is_pain7mo ago
if they're used in the same context maybe i would use a bool if not i would put the query in a class and reuse it adding details in the repository/class where it's needed in fact i would not probably just write the query but the separate parts, although it depends
Core
CoreOP7mo ago
what do you mean by "used in the same context" ?
this_is_pain
this_is_pain7mo ago
i don't know the code is yours both used by the same endpoint, or used by the same object
sibber
sibber7mo ago
why even have a method?
Core
CoreOP7mo ago
Because the query is exactly the same, the only difference is the use of .AsNoTracking(). That's why I'm trying to reuse it
sibber
sibber7mo ago
copy pasting is fine unless the query is very long or complex
Core
CoreOP7mo ago
Got it thanks
sibber
sibber7mo ago
$close
MODiX
MODiX7mo ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?