使用EF6代码优先使用代码不会填充计算值。我有一个计算的日期时间字段(FechaCreacion)。我怎样才能在Effort中模拟它,所以在saveChanges()之后用DateTime.Now填充它?
这篇文章使用Effort(EF测试工具)和计算列是DB First而不是Code First作为我的例子,但似乎也没有答案。
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时,该字段获取空日期值。