I’m getting sick with this problem. I have some tables that have contentes launched in a specific date to a region.
I’m making an MVC app and it will show a chart of grow by date.
I’m trying to make a method that recieves int days and count each day the amount of contents launched til that day. Example:
Region en-US
- Content X – Date 12/03/2010
- Content Y – Date 12/03/2010
- Content Z – Date 13/03/2010
Region pt-BR
- Content A – Date 13/03/2010
- Content B – Date 14/03/2010
Region ja-JP
- Content J – Date 15/03/2010
So the chart must show:
Date 12/03/2010:
- en-US: 2
- pt-BR: 0
- ja-JP: 0
Date 13/03/2010
- en-US: 1
- pt-BR: 1
- ja-JP: 0
Date 14/03/2010
- en-US: 0
- pt-BR: 1
- ja-JP: 0
Date 15/03/2010
- en-US: 0
- pt-BR: 0
- ja-JP: 1
I feel powerless trying to make this query.
Anyone can help?
Here, other method I’ve created to show day-by-day numbers per Country:
public KeyValuePair<string, List<KeyValuePair<string, int>>>[] ChartDayByDay(int days, string locale)
{
KeyValuePair<string, List<KeyValuePair<string, int>>>[] contagens;
DateTime inicio = DateTime.Today.AddDays(days * (-1));
var qry = from c in db.XBLRegionalInfos
where c.PublishDate != null
&& c.PublishDate > inicio
select c;
if (!String.IsNullOrEmpty(locale))
qry = qry.Where(x => x.RegionId == locale);
var qry2 = (from c in qry
group c by c.RegionId into g
let count = g.Count()
where count > 0
select g).ToList();
var regioes = db.XBLRegions.ToList();
contagens = new KeyValuePair<string, List<KeyValuePair<string, int>>>[qry2.Count];
for (int i = 0; i < qry2.Count; i++)
{
for (int j = 0; j < qry2[i].Count(); j++)
{
var pais = qry2[i].ElementAt(j).Region.Country;
contagens[i] = new KeyValuePair<string, List<KeyValuePair<string, int>>>(
pais, CountPeriod(days, qry2[i].ElementAt(j).RegionId));
}
}
return contagens;
}
This works with linq to objects at least: