C
C#4mo 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
HtmlCompiler
HtmlCompiler4mo 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
CoreOP4mo ago
what do you mean by "used in the same context" ?
HtmlCompiler
HtmlCompiler4mo ago
i don't know the code is yours both used by the same endpoint, or used by the same object
sibber
sibber4mo ago
why even have a method?
Core
CoreOP4mo 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
sibber4mo ago
copy pasting is fine unless the query is very long or complex
Core
CoreOP4mo ago
Got it thanks
sibber
sibber4mo ago
$close
MODiX
MODiX4mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server