Problem with query with Group By
Posted: Thu 18 Jul 2013 20:27
Hi,
I have a problem when I run a query that have "group by" in it.
I have the following code :
This code ask data in a table between 2 dates and group them by date. It work well the first time I execute de query. If I ask the data between 2013-07-18 to 2013-07-20 I will get all the right data. In my application I can change the start and end date and execute de query again. If I change the date after I have execute the first query and I ask data between 2013-07-18 to 2013-07-22 and I execute the query again, I will only get the data between 2013-07-18 to 2013-07-20. If I execute my application again, but ask my first query for data between 2013-07-18 to 2013-07-22 it will work well. If I ask for the second query the data between 2013-07-18 to 2013-07-20 it will work well also, because 2013-07-20 is smaller than the end date (2013-07-22) that I asked for the first query, but If I ask after to get data between 2013-07-18 to 2013-07-25, I will only get data between 2013-07-18 and 2013-07-22 because it's the range I asked for my first query.
I have also the same query without grouping :
With this query all is working fine! I can change my dates as I want and I always get the good result. I get the problem only with the query with "Group by"
I would like to know if you have any idea why I get this problem.
Thank you in advance!
I have a problem when I run a query that have "group by" in it.
I have the following code :
Code: Select all
var horairesByDate = from item in ((App)Application.Current).db.Horaires
where item.Complete == false && item.Datefin >= startDate.Date && item.Datedebut < endDate.Date
orderby item.Datedebut
group item by item.Datedebut.Date
into groupedByDate
select groupedByDate;
var myList = await horairesByDate.ToListAsync();
// var myList = await horairesByDate.ToListAsync();
foreach (var List in myList)
{
var currentList = List;
foreach (var horaire in currentList)
{
System.Diagnostics.Debug.WriteLine(horaire.Datedebut.ToString() + " " + horaire.Datefin.ToString() + " ID : " + horaire.Id + " Evénement : " + horaire.Evenement);
}
}
GroupedItems.Source = horairesByDate;
I have also the same query without grouping :
Code: Select all
((App)Application.Current).db = new TtvDevV1DataContext()
bool exist = ((App)Application.Current).db.DatabaseExists();
var query = from item in ((App)Application.Current).db.Horaires
where item.Complete == false && item.Datefin >= dateDebut && item.Datedebut < dateFin
orderby item.Datedebut
select item;
var currentList = await query.ToListAsync();
foreach (var horaire in currentList)
{
System.Diagnostics.Debug.WriteLine(horaire.Datedebut.ToString() + " " + horaire.Datefin.ToString() + " ID : " + horaire.Id + " Evénement : " + horaire.Evenement);
}
ItemGridView.ItemsSource = currentList;
I would like to know if you have any idea why I get this problem.
Thank you in advance!