禁用关系上的外键约束 [英] Disable Foreign Key constraint on relation

查看:97
本文介绍了禁用关系上的外键约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我们的数据库,我们提供的信息仅在外部提供。要从数据库中使用CF访问它,我们将视图建模为实体。这给出了一个问题,因为它将为我们而不是视图创建一个表。我们的观点是指向另一个数据库中的
表,该表在我们的控制之外重新创建/重新填充。当我们尝试用我们的视图替换表格时,我们遇到了一个问题:表格存在外键关系,因此我们无法删除表格,而且

For our database we have information that is only available externally. To access it from within the database and with CF we modelled the view as an Entity. This gives a problem as it will create a table for us instead of a view. Our view is pointing to a table in another database which is recreated/refilled outside our control. When trying to replace the table with our view we hit a bump: There is a foreign key relation to the table and thus we cannot remove the table, also it 

现在我的问题是:

 


  1. 我们如何禁用某个外键约束的创建?
  2. 我们如何禁用一个特定表的创建? (或更多?)
  3. 是否有更好的解决方案来访问外部数据?也许复制?


有没有人有想法?

推荐答案

如果使用Code First创建数据库,则只能使用表,并且每个实体类型都需要有一个表。您可以在创建数据库后运行其他DDL,以便删除约束和表,并将其替换为
。如果在运行时不存在约束,EF将不关心。

If you are using Code First to create the database then you are restricted to using tables and there needs to be a table for each entity type. You could run additional DDL after database creation in order to remove the constraint and table and replace it with the view. EF won't care if the constraint isn't there at runtime.

~Rowan


这篇关于禁用关系上的外键约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆