Strengthen foreign key references in an effort

I use Effort in Visual Studio and C # to recreate and unit test the database. I am writing a class for one table, so I only populate the database with objects from this table. My problem is that the Effort database wants the foreign keys of the object to refer to the actual objects in the database.

My mistake

System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating records. See Internal Exception for more details.

System.Data.Entity.Core.UpdateException: An error occurred while updating records. See Internal Exception for more details.

System.Reflection.TargetInvocationException: An exception was thrown by the call target.

NMemory.Exceptions.ForeignKeyViolationException: Foreign key violation [Table1 :: SettingsId]. The key value [0] does not exist in the reference table [Table2 :: SettingsId] .. Error code: RelationError

Since this particular table has many foreign keys to objects that have many other foreign keys, this will require a lot of work. Is there a way in Effort to disable this so that I can check this table separately?

+4
source share
3 answers

. , , , . , , / , .

+1

. , , .sql. Entity Framework , .

0

.edmx . :

Visual Studio File- > New- > Data- > Entity DataModel. "EF Designer ". SQL Server app.config "testConnectionString".

, . .

Effort ( .edmx) CreateTransient, :

EntityConnection connection = Effort.EntityConnectionFactory.CreateTransient("name=testConnectionString");

MyDbContext context = new MyDbContext(connection);

, .

This is due to a warning, but if the code you are testing uses any navigation properties that depend on foreign keys, it will not work. This makes me wonder how valuable such “unit testing” is.

0
source

Source: https://habr.com/ru/post/1648566/


All Articles