Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity SQL compare datetime without milliseconds

I'm trying to fetch some records from MSSQL DB using EntityObject with EntitySQL query. The field i'm using to filter is type of datetime. The generated query projected without millisecond, to the SQL Server returns nothing. When i'm adding the milliseconds, i get results.

How can i use the EntitySQL to get result without the milliseconds?

thanks.

like image 981
Tamir Avatar asked Oct 15 '22 15:10

Tamir


2 Answers

It's not elegant, but this worked for me:

foos.SingleOrDefault(f => f.EntryDate.Year == bar.EntryDate.Year &&
                          f.EntryDate.Month == bar.EntryDate.Month &&
                          f.EntryDate.Day == bar.EntryDate.Day &&
                          f.EntryDate.Hour == bar.EntryDate.Hour &&
                          f.EntryDate.Minute == bar.EntryDate.Minute &&
                          f.EntryDate.Second == bar.EntryDate.Second);
like image 82
Christian Payne Avatar answered Oct 30 '22 21:10

Christian Payne


One way to do it is to create a view of your data, where your datetime column is converted to smalldatetime (which does not have milliseconds).

Then add the view to your entity framework model, and read the data through the view.

Hope this helps

Shiraz

like image 44
Shiraz Bhaiji Avatar answered Oct 30 '22 23:10

Shiraz Bhaiji