C
C#6mo 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
FestivalDelGelato
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
CoreOP6mo ago
what do you mean by "used in the same context" ?
FestivalDelGelato
i don't know the code is yours both used by the same endpoint, or used by the same object
sibber
sibber6mo ago
why even have a method?
Core
CoreOP6mo 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
sibber6mo ago
copy pasting is fine unless the query is very long or complex
Core
CoreOP6mo ago
Got it thanks
sibber
sibber6mo ago
$close
MODiX
MODiX6mo ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?