Compare DateTime Objects in EFCore 2.1.1 and .NET Core 2.1

.net-core c# entity-framework-core

Question

I am trying to select data using EFCore 6.0 in .NET Core 2.1 trying to check whether a datetime column is less than DateTime.Now.

I have tried using DbFunction.DiffMinutes() but is of no use as I am getting no such function in the DbFunction class.

Any idea?

1
3
4/13/2020 4:02:38 AM

Popular Answer

Add Microsoft.EntityFrameworkCore v2.1.1 from Nuget Packages. Then, use SqlServerDbFunctionsExtensions class for getting Date comparison. Do the following what I have done in my application. I have found difference in minutes between Date1 and Date2:

DbFunctions dfunc = null;
IQueryable<TableName> lQueryableTableName = lObjInitDbContext.gObjServerAuditHistoryDbContext
   .ServerAuditHistorys
   .Where(x => SqlServerDbFunctionsExtensions
       .DateDiffMinute(dfunc, Convert.ToDateTime(Date1), Convert.ToDateTime(Date2)) < 1);

Hope this will help you!!!

6
6/28/2018 11:45:25 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow