使用 EF6 的 Code First 无法填充计算值。我有一个日期时间字段 (FechaCreacion) 是计算的。如何在 Effort 中模拟它,以便在保存更改后用 DateTime.Now 填充它?这篇文章 Using Effort (EF Testing Tool) with Computed Column 是 DB First 而不是 Code First,但似乎也没有得到答案。
在SQL Server中运行良好,但在使用Effort进行单元测试时,该字段会获得空日期值。
EffortConnection connection = (EffortConnection)DbConnectionFactory.CreateTransient();
using (var c = new ControlConfigContext(connection))
{
c.Database.CreateIfNotExists();
CambioRepositoryTestLoadData.Load(c);
string direccionMac = "FFFF";
var repo = new CambioRepository(c);
var primerConcesionarioTerminal = repo.GetPrimerConcesionarioTerminal(direccionMac);
Assert.AreEqual("terminal1", primerConcesionarioTerminal.Terminal);
}
这个值在SQLServer中是通过GetDate()计算得出的。
this.Property(t => t.FechaCreacion).HasColumnName("FechaCreacion").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
在SQL Server中运行良好,但在使用Effort进行单元测试时,该字段会获得空日期值。