✅ Ef Query
I have a var called SaleD is is bassed of the model sales which contiand a public product product and qaunitty and product id etc. I want to write a query to select SaleD.Product and ordrbydecedning a the total SaleD quanity sold for each saleD product.
50 Replies
what do you have so far?
i tried but idont how to do it
so i have nothing right now
we can't go off nothing
even if your attempt was wrong we can show you where it's wrong
ok ill show you my attempt
ya its complpety wrong
share actual code
not something you typed out in here
this is a place where you can come with a specific problem and details and show us what you've tried so we can help you, not a place for someone to do all the work for you
one sec
i changed it up but sitll no work
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/i cant get disocrd on the laptop which the code is
then it's going to be very difficult to help
anyway, read the error message and see what it says
it runs like a potato
look at it this way: the more effort you put into getting help, the better help you will receive
food dose not contain a defination
so what does that mean?
i am just confused how to write the query
this isn't a query problem yet
you need to know what members you defined on your own types
if a food item doesn't have a
salesData
property then what you wrote doesn't make senseslaes data contains foods
but you have a food item
what properties are on your food item?
my bad
sales data also contians quanity
i removed food item
but you clearly don't have a
salesData
on foodItem
don't remove random things
i want you to understand why you're getting the error you're gettingi have sales data
do you understand the error you had?
yes it was a mistake
what was the mistake?
food item was not thing
i don't know what that means
like i never had it
then what type is in the
_context.food
dbset?yes
but sales data is a vairble contaning orderedfood
orderedfood is linked to foods
where are you getting sales data from?
its a var i made
okay, here's the deal
i did this as i want to aply filters
i'm going to take a break and give you some time to get your thoughts together
so you can clearly explain your code and your problem
ight
yes
i'm not going to try and pull it out of you like this
ok
5 minutes
share as much code as possible
that might be hard if you don't have discord on the same PC, but it's very important
specifically your dbcontext and entity definitions
at least try to get on discord in a browser or something
ight
Hi this is the probelm the qurey reutrns null sales data is not null i run debuger.
What i want to get a list of all the food in sales data and display the sum of the quanity feild.
So it will go throguh sales data group by food and sum all the quntity feilds where the product is the same
@jIMMACLE
@jIMMACLE
i'm still waiting for you to do what i asked
i did
i made some progress
i found out this works
Var QuanititySolded = salesData.GroupBy(a => a.foods.Id).OrderBydescending(a => a.sum( a => a.Quanity));
the probelm i have is new I dont know how to acces quantiy sold to actually see if it works or not.
because
QuanititySolded
is a collection, not a value
look at what OrderBydescending
returnshow
how do i show in view or see vlaues of the collection
there are no values because you have not materialized the query
all you've done so far is build a query, not execute one
you should look through some guides on how EF Core works
is it hard to do
is what hard to do?
This
if you don't know what i mean by that you need to go back and reintroduce yourself to how EF Core works
or go to your teacher/professor because at this point you aren't providing the information i'm asking for and i'm not going to spoonfeed you an answer