[英]Entity Framework Code First vs DB First: Trap Relationship Constraint Problems
Two questions: 两个问题:
Does Entity Framework (Code First) trap "Relationship Constraint" problems (such as foreign key constraint violation) before it hits database ie in the application. 实体框架(代码优先) 在命中数据库(即在应用程序中) 之前是否捕获“关系约束”问题(例如,违反外键约束)。
As far as I know, Entity Framework (DB First) does not trap "Relationship Constraint" problems in the application space; 据我所知,实体框架(数据库优先)并未在应用程序空间中捕获“关系约束”问题。 it waits until SaveChanges method fails due to constraint violation error(s) get raised from database.
它会一直等到由于数据库违反约束错误而导致SaveChanges方法失败。 Is there any way to force it check the relationships automatically ?
有什么方法可以强制它自动检查关系?
Nope. 不。
Nope. 不。
Sorry. 抱歉。
You really don't want that - another user might insert data into the DB making a foreign key reference suddenly valid. 您确实不希望这样做-另一个用户可能将数据插入数据库,使外键引用突然生效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.