我有一个看起来像这样的测试用例:
[TestMethod]
public void Things_can_be_saved()
{
var ts = DateTime.Now;
var thing = new Thing()
{
Name = "Some name",
TimeStamp = ts
};
// save it
var context = new MyDataContext(testDb);
context.Things.Add(thing);
context.SaveChanges();
// pull from a fresh context so we know it's a db pull not cached
var context2 = new MyDataContext(testDb);
var fetched = context2.Things.FirstOrDefault(t => t.TimeStamp == ts);
Assert.AreEqual(thing.Name, fetched.Name);
}
所以,当我运行它时,我可以查看数据库并查看数据库中存在的“事物”。我可以看到它存储的Timestamp列等于运行时ts变量中的值。但'fetched'为空,表示EF无法在FirstOrDefault查询中找到它。有没有关于DateTime相等的东西?