Hi, I am retrieving some products from DB and I ended up with this:
Is there any way to merge those two queries to just single one? I know I can just retrieve all objects from DB and group them locally to save one DB call, but I’d like to avoid retrieving data I don’t need. And learn some more complex queries:)
Basically I need this output:
but I don’t really like getting just code from by separate query.
Thank you!
The product isn’t used in quantities, and is a FirstOrDefault(), so I even in SQL these are two separate queries.
What you can try is FutureValue and Future. This defers execution of queries, effectively sending two or more queries as one SQL statement.
https://entityframework-plus.net/ef-core-query-future-value
https://entityframework-plus.net/query-future
Futures was something that was pretty handy in NHibernate that EF never had out-of-the-box.
Sometimes though, it may be better building a stored proc for more complex queries.
I meant if there is some way with grouping it (somehow) to get single result + multiple another.
My previous query looked like this:
I’ve got everything I needed in single query but that Code
was same in all objects which was unnecessary. I was still making another object from it so it didn’t really matter, but I am still curious if there is better way to do it. (maybe this was better than my current two queries?)
Thank you, I will look at those futures.
Doesn’t this already fetch the product anyway?
It generates INNER JOIN
for those and from DB comes only Quantity
and Date
.
C# devs
null reference exceptions