0

I have a code first EF Model with a simple one(PartDetails)-to-many(Parts) relationship.

While the system is offline the lookup (PartDetails) table is purged and re-populated by external job, violating the constraint.

modelBuilder.Entity<Part>().HasOptional(e => e.PartDetails)
                           .WithMany()
                           .HasForeignKey(k => k.PartDetailsId);

I have tried .Map and other variants but all create the DB constraint.

How can I prevent EF from creating the DB FK constraint using the fluent API?

I understand this may not be the best architectural approach but I'm stuck with it. If I can't find a solution to do this with the Fluent API I will manually drop the constraint in a migration script or drop and re-add the constraint during the purge job.

4

1 回答 1

0

您可以使用Sql("DROP CONSTRAINT...").

但更好的架构方法是在清除作业期间删除并重新添加约束。听起来清除工作是问题所在。约束非常重要。

于 2014-09-17T13:41:09.560 回答