C
C#11mo ago
🙈

✅ 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
Jimmacle
Jimmacle11mo ago
what do you have so far?
🙈
🙈OP11mo ago
i tried but idont how to do it so i have nothing right now
Jimmacle
Jimmacle11mo ago
we can't go off nothing even if your attempt was wrong we can show you where it's wrong
🙈
🙈OP11mo ago
ok ill show you my attempt ya its complpety wrong
Jimmacle
Jimmacle11mo ago
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
🙈
🙈OP11mo ago
one sec i changed it up but sitll no work
Jimmacle
Jimmacle11mo ago
$code
MODiX
MODiX11mo ago
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/
🙈
🙈OP11mo ago
i cant get disocrd on the laptop which the code is
Jimmacle
Jimmacle11mo ago
then it's going to be very difficult to help anyway, read the error message and see what it says
🙈
🙈OP11mo ago
it runs like a potato
Jimmacle
Jimmacle11mo ago
look at it this way: the more effort you put into getting help, the better help you will receive
🙈
🙈OP11mo ago
food dose not contain a defination
Jimmacle
Jimmacle11mo ago
so what does that mean?
🙈
🙈OP11mo ago
i am just confused how to write the query
Jimmacle
Jimmacle11mo ago
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 sense
🙈
🙈OP11mo ago
slaes data contains foods
Jimmacle
Jimmacle11mo ago
but you have a food item what properties are on your food item?
🙈
🙈OP11mo ago
my bad sales data also contians quanity i removed food item
Jimmacle
Jimmacle11mo ago
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 getting
🙈
🙈OP11mo ago
i have sales data
Jimmacle
Jimmacle11mo ago
do you understand the error you had?
🙈
🙈OP11mo ago
yes it was a mistake
Jimmacle
Jimmacle11mo ago
what was the mistake?
🙈
🙈OP11mo ago
food item was not thing
Jimmacle
Jimmacle11mo ago
i don't know what that means
🙈
🙈OP11mo ago
like i never had it
Jimmacle
Jimmacle11mo ago
then what type is in the _context.food dbset?
🙈
🙈OP11mo ago
yes but sales data is a vairble contaning orderedfood orderedfood is linked to foods
Jimmacle
Jimmacle11mo ago
where are you getting sales data from?
🙈
🙈OP11mo ago
its a var i made
Jimmacle
Jimmacle11mo ago
okay, here's the deal
🙈
🙈OP11mo ago
i did this as i want to aply filters
Jimmacle
Jimmacle11mo ago
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
🙈
🙈OP11mo ago
ight yes
Jimmacle
Jimmacle11mo ago
i'm not going to try and pull it out of you like this
🙈
🙈OP11mo ago
ok 5 minutes
Jimmacle
Jimmacle11mo ago
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
🙈
🙈OP11mo ago
ight
🙈
🙈OP11mo ago
No description
🙈
🙈OP11mo ago
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
Jimmacle
Jimmacle11mo ago
i'm still waiting for you to do what i asked
🙈
🙈OP11mo ago
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.
Jimmacle
Jimmacle11mo ago
because QuanititySolded is a collection, not a value look at what OrderBydescending returns
🙈
🙈OP11mo ago
how how do i show in view or see vlaues of the collection
Jimmacle
Jimmacle11mo ago
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
🙈
🙈OP11mo ago
is it hard to do
Jimmacle
Jimmacle11mo ago
is what hard to do?
🙈
🙈OP11mo ago
This
Jimmacle
Jimmacle11mo ago
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
Want results from more Discord servers?
Add your server