I have run into a scenario where I need to bulk delete on a specific date time. It seems that the EF+ batch delete function doesn't correctly equate date time and perform the action.
It does work fine on other field types, but just not DateTime. Is there some special formatting I should be doing to perform this action properly?
The backend SQL Server table has the FileCreatedDate
as DateTime2(7)
. And records all contain the DateTime.UtcNow
date/time that is specified in the code, since an initial pass prior to this code created those records. This is a fallback to clean out the records that got created if an error occurred.
I have the following code:
var fileCreatedDate = DateTime.UtcNow;
using (var db = new MyContextDb())
{
db.SampleModel.Where(e => e.FileCreatedDate == fileCreatedDate).Delete();
}
This code doesn't work. It doesn't delete the records whose time matches the criteria.
Any ideas what might be the problem?