Using LocalDB for Integration/Unit Tests

Long did I hold this perception that integration tests are hard. With EF core, they are actually really easy. Instead of using SQL Sever, we can substitute with LocalDB. Run this before running the tests and you'll have your db setup. After calling EnsureCreated you can add things into the database.

The ALTER TABLE statement conflicted with the FOREIGN KEY constrain

I've been trying to apply a new migration and I was getting the following error: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_dbo.Parent_dbo.Childs_ChildId". The conflict occurred in database "parents_db", table "dbo.Childs", column 'ChildId'. In my case, the table contained data. Therefore, either you have to assign a default value, set it as ... Read more The ALTER TABLE statement conflicted with the FOREIGN KEY constrain

Using InverseProperty and ForeignKey Attributes

InverseProperty and ForeignKey are (arguably) the most commonly used attribues in Entity Framework when developing in code-first approach. They help greatly simply the job of managing our models. Foreign Key In order to introduce foreign key to our code we need to specify to what objects it maps to. So there are two things that ... Read more Using InverseProperty and ForeignKey Attributes