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.
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.
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