Disable Foreign Key Constraint Code First EF
c#, ef-code-first, entity-framework, foreign-keys, sql-server
Solution
One solution I found was to run my own custom migration like :
`Sql("ALTER TABLE dbo.ProductItems NOCHECK CONSTRAINT [FK_dbo.ProductItems_dbo.Services_ProductItemTypeId]");`
Do not know whether that is the only way. Still open to suggestions.
Problem
If I wanted to disable foreign key constraint on a relationship. I would do the following if I was editing in database: But I want the disabling of a foreign key constraint on a relationship in my migration file or in my configuration or in my model in the form of annotation in respect to 'Code First' approach. So far I came up with nothing but I tried with `.WillCascadeOnDelete(false)` though. I also noticed that EF does not care if I take the liberty of disabling foreign key constraint from database but that would violate code first approach in my perspective. So, any suggestion is highly appreciated.