CodeFirst Foreign Keys "Not for Replication" RRS feed

  • Question

  • I would like to know if there is a way to mark the foreign keys in my model as Not for Replication so that they show in the database as Enforce for Replication = false.

    Currently, we are dropping every foreign key and re-adding them manually with the ATLER TABLE statement and want to know if there is a better way?

    IF EXISTS (SELECT * FROM sys.foreign_keys WHERE name = N'AccountRequest_GeographicEntity')  ALTER TABLE [dbo].[AccountRequest] DROP CONSTRAINT [AccountRequest_GeographicEntity]; 
    ALTER TABLE [dbo].[AccountRequest]  WITH CHECK ADD CONSTRAINT [AccountRequest_GeographicEntity] FOREIGN KEY([GeographicEntityID]) REFERENCES [dbo].[GeographicEntity] ([GeographicEntityID]) NOT FOR REPLICATION;



    Thursday, January 7, 2016 4:25 PM