Linq+File
Can you give me some tips ?
I only created seed file info writer to create and fill file with data (Step 1 and 2)
Let's make two txt.file
1) Customers.txt
2) Orders.txt
Customers table
3: CustomerID, CustomerName
1|Lasha
2|Beka
3|Dimitri
Orders table
: OrderID, Date, Product, Price, CustomerID
1|20201212|Coca-cola|3.0|1
2|20201111|Pepsi|3.0/2
3|20200909|Staropramen|4.0/2
4|20201212|Argo|2.0|3
There must be at least 5 users and at least 20 orders. (Fill in the details as you wish)
We need to extract the following type of report:
1. The number of orders for each customer. For example: CustomerID - 1, Order Count-2
The total price of each customer's orders. For example: CustomerID - 1, SumAmount -2 10.5
3. Minimum order price for each customer. For example: CustomerID - 1, MinAmount-0.6
4. Only customers who have more than one order. CustomerID-1, Order Count-2
5. Only customers whose average order is greater than 10. CustomerID-1, AvgAmount-12.5
Best solution is with Aggregate functions in Ling, as well as Having clauses in Ling. Classic Foreach should only be used when printing.
8 Replies
i can't understand one thing i need to take data from file like this ?
That seems reasonable, yes.
The way LINQ works is that it works on sequences, and if you use that method your files are read into string arrays, aka a sequence of strings
i'll make the same for orders and then join them by ID
and after i'll make main task
yes it's ugly code , but i'm not using AI and struggling by myself (i've some knowledge , but s*ck at basics ...)
No thats fine
not ugly at all, pretty standard for "linq golf" 🙂
you missed an
m on the int.Parse btw 😛Though, if you want to make LINQ pretty, newlines are your friend
You usually see
rather than
The number of orders for each customer. For example: CustomerID - 1, Order Count-2
For this i wanted to group orders by customer ids and then count for each customer , but since using foreach is forbidden i'm confused
wdym?
you dont need to group
and even if you did, you wouldnt need a foreach
yeah you are right i was bit confused cuz couldnot get grouped values from IEnumerable<Grouping>