C
C#3mo 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
Omnissiah
Omnissiah3mo 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
CoreOP3mo ago
what do you mean by "used in the same context" ?
Omnissiah
Omnissiah3mo ago
i don't know the code is yours both used by the same endpoint, or used by the same object
sibber
sibber3mo ago
why even have a method?
Core
CoreOP3mo 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
sibber3mo ago
copy pasting is fine unless the query is very long or complex
Core
CoreOP3mo ago
Got it thanks
sibber
sibber3mo ago
$close
MODiX
MODiX3mo 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