I am using Effort in Visual Studio and C# to recreate and unit test a database. I am writing a class for a single table and so I am only populating the database with objects from that table. My problem is that the Effort database wants the object's foreign keys to reference actual objects in the database.
My error is
System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details.
System.Data.Entity.Core.UpdateException: An error occurred while updating the entries. See the inner exception for details.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
NMemory.Exceptions.ForeignKeyViolationException: Foreign key violation [Table1 :: SettingsId]. The key value [0] does not exists in the referenced table [Table2:: SettingsId].. Error code: RelationError
As this particular table has many foreign keys to objects that have many other foreign keys it would require a lot of work. Is there any way in Effort to turn this off so that I can test this table alone?
I ran into this problem too and wanted to test the table in the scope of the larger database. You can make a helper method that will just instantiate everything you need and pass the database or table with references as a result. That helps because you can call it from whichever test method/class you need to and whenever you need to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With