How do I 'build' a QUERY with EF Core?
Essentially I had an endpoint that can take multiple query string params, most are optional, so I want to check first if the query parameter exists - then if it does "add" it to the query. This keeps to be sending me errors and doesn't feel efficient; have I missed something?
![](https://utfs.io/f/ed67e0f5-e6e5-474f-9aed-ac5e7043bbac-4pl4mu.png)
12 Replies
Like this
Ahh, so build the queryable; then it is
called
when you
![airquoteleft](https://cdn.discordapp.com/emojis/898198984366096434.gif)
![airquoteright](https://cdn.discordapp.com/emojis/898199002728763442.gif)
.ToListAsync()
Yep
Interesting!
.ToListAsync()
, .FirstOrDefaultAsync()
, CountAsync()
etc. are where the query gets resolvedSo I guess my current impl, is just executing the query then I'm transforming the shape of the data based on my ![signty](https://cdn.discordapp.com/emojis/958691615302615090.png)
![signty](https://cdn.discordapp.com/emojis/958691615302615090.png)
Your current code doesn't really do anything
Since the query doesn't get modified in place
You just call the
.Where()
on the query... and discard it![AwkwardKid](https://cdn.discordapp.com/emojis/529050100480344074.gif)
Good:
Bad:
Ahhhhh! So just update the query with it
All those methods — besides the ones that resolve the query — return an
IQueryable
, they're not void
YeahThanks!