我正在尝试检查 aDateTime
是否已经在我的数据库中。
我已经分解了下面的代码,以便更好地了解正在发生的事情,但是尽管我尽了最大努力,但 dateChecks 将始终返回一个空列表。
var MyDate = DateTime.Now;
foreach (var milestone in mtMilestone.Milestones)
{
var checkIfAlreadyPulled = _ipdb.JsonDataReleases.
Where(x => x.ReleaseId == mtMilestone.ReleaseId).ToList();
var dateChecks = checkIfAlreadyPulled.
Where(x => EntityFunctions.Equals(x.LastUpdated, MyDate)).ToList();
if (!dateChecks.Any())
{
/* do stuff what this does it it makes a new entry into the JsonDataReleases
db using MyDate as the new LastUpdated value. */
}
/* Does more unrelated stuff... */
}
编辑:所以我想通了!
事实证明,当 DateTime.Now 被保存为 sql 数据库中的 LastUpdated 值时,它会切断毫秒。
var now = DateTime.Now;
var MyDate= new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);