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