Product Name
|
Product Price
|
DateTime
|
Prod1
|
66
|
22/10/2013
|
Prod2
|
55
|
21/03/2014
|
.
|
.
|
.
|
.
|
.
|
.
|
.
|
.
|
.
|
Now I divided this list into two more resultant list by
grouping,
Var list1=Products.GroupBy(p =>
p.DateTime.Value.Hour);
Hours
|
Counts
|
1
|
23
|
2
|
66
|
.
|
.
|
.
|
.
|
.
|
.
|
Var list2=Product. .Where(p=>p.product_price
<= 50).GroupBy(p => p.DateTime.Value.Hour);
Hours
|
Counts
|
1
|
20
|
2
|
55
|
.
|
.
|
.
|
.
|
.
|
.
|
Now I want to divide list2 counts by list1 counts
one by one and store it in third list as result,
Hours
|
Counts
|
1
|
20 / 23
|
2
|
55 / 66
|
.
|
.
|
.
|
.
|
.
|
.
|
how can I do this or is there any other simple way
of doing it in Linq To Entity.
Solved,
var result = from
list1 in
(from p in
Products group p by
(p.DateTime.Value.Hour) into Grp select new { Hours=Grp.Key, Count=Convert.ToDouble( Grp.Count())})
join list2 in
(from p in
Products where p.ProductPrice<=50 group p by
(p.DateTime.Value.Hour) into Grp select new
{Hours=Grp.Key,Count=Convert.ToDouble(
Grp.Count()) })
on list1.Hours equals
list2.Hours
select new
{
Hours = list1.Hours,
Counts =Convert.ToDouble( list2.Count / list1.Count)
};