Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unenforce foreign key references in Effort

Tags:

c#

effort

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?

like image 631
A_Arnold Avatar asked Jul 20 '16 19:07

A_Arnold


1 Answers

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.

like image 142
blah blah Avatar answered Oct 23 '22 01:10

blah blah