使用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時,該字段獲取空日期值。