I am creating a WPF app using C#, Entity Framework and SQL Server 2008 R2. I am trying to fire the following query.
Select Convert(nvarchar(10),bk.BookingDate,103) as Date, Count(*)
from Booking bk
where
Convert(date,bk.BookingDate) between '2014-10-01' and '2014-10-31'
and bk.IsDeleted = 0
group by Convert(nvarchar(10),bk.BookingDate,103)
order by 1
This query works if directly fired on SQL Server prompt and fetches results.
However when I am trying using Entity Framework I am getting NULL value.
var values = context.Database
.SqlQuery<KeyValuePair<string, int>>(query)
.ToList<KeyValuePair<string, int>>();

- Is it because I am using a KeyValue pair in the method call?
- Is there any alternative of doing this using Entity Framework?
- Or should I use old style database connection and command to run this query?