Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq date and datetime comparer

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.'

like image 344
Luis Avatar asked Mar 01 '26 17:03

Luis


1 Answers

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
like image 94
Ivo Avatar answered Mar 04 '26 08:03

Ivo