2

I need to get the query of the day, the problem is that I'm getting an error when I try to compare the value that comes from the DB (which is a DateTime), against the DateTime.Today.Date value.

What I'm trying to achieve is to get the registers of the day.

List<Client> _cliente = from c in db.Cliente
                        join v in db.Vendedor
                        on c.IDVendedor equals v.IDVendedor
                        where v.Fecha.Date.Equals(DateTime.Today.Date)

This is what I'm getting: 'The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.'

Magnus
  • 45,362
  • 8
  • 80
  • 118
Luis
  • 5,786
  • 8
  • 43
  • 62

2 Answers2

9

Maybe you can do something like this:

var today = DateTime.Today;
var tomorrow = today.AddDays(1);

List<Client> _cliente = from c in db.Cliente
                    join v in db.Vendedor
                    on c.IDVendedor equals v.IDVendedor
                    where v.Fecha >= today && v.Fecha < tomorrow
Ivo
  • 8,172
  • 5
  • 27
  • 42
  • 1
    This is based on the fact that DateTime.Today will return the date with the time set to 00:00:00. – Ivo Jan 10 '12 at 17:15
0

You can use the C# standard library -- There is a time interval type (subtract one time from another, then get the absolute value of the number of days, like so:

List<Client> _cliente = from c in db.Cliente
                    join v in db.Vendedor
                    on c.IDVendedor equals v.IDVendedor
                    where Math.Abs((v.Fecha.Date - DateTime.Today).Days) <= 1
Hogan
  • 69,564
  • 10
  • 76
  • 117