Using Effort (EF Testing Tool) with Computed Column

c#-4.0 database effort entity-framework integration-testing


I have a number of integration tests which access the DB directly - create test prerequisite objects - performs the tests and then cleans up afterwards - however I wonted to try out the same approach in-memory.

I have just used Effort in my project and it works very easily. However I've hit a problem that I have been trying - but unable to solve.

One of the tables that I need filled up with dummy data - as a test prerequisite - contains a computed column (nvarchar, not null). For the scope of the test I really don't care about that column's value - but even if I try to insert dummy data, my data is ignored and then I get hit with an error:

"Column 'x' cannot be null. Error code: GenericError"

In my tests I am using the same edmx file as is used by the actual code. This prevents me from constantly updating the edmx copy.

Is there a way in which I can force the test to update the edmx (at runtime) so that column is a nullable non-computed column? [overriding OnModelCreating] or is there way to insert a default value (anything goes for this column) to stop this error? [overriding SaveChanges]

I have currently tried the following:

  • Attaching the objects using .Attach() instead of .Add()
  • Setting the EntityState to Unchanged after adding
  • Forcing the value through Entry.OriginalValues [this values since entity is in Added state]


I have tried overriding the OnModelCreating method, but to no avail since this is DB-First.

modelBuilder.Entity<Entity_Name>().Property(p => p.x).IsOptional().HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None);
1/30/2015 10:29:27 AM

Popular Answer

The reason of the problem was a bug in the Effort database. When the computed column is based on non-nullable columns, the computed column would also automatically become non-nullable. Therefor, the Effort database was expecting a non-null value. With the latest update the problem is resolved. You have to set the global EntityFrameworkEffortManager.UseDefaultForNotNullable flag as true.

See the issue on github

3/10/2019 2:52:52 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow