✅ 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
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
what do you mean by "used in the same context" ?
i don't know the code is yours
both used by the same endpoint, or used by the same object
why even have a method?
Because the query is exactly the same, the only difference is the use of
.AsNoTracking()
. That's why I'm trying to reuse itcopy pasting is fine
unless the query is very long or complex
Got it
thanks
$close
If you have no further questions, please use /close to mark the forum thread as answered