[英]Does an DB-First Entity context have to match the database schema, even for unused tables?
I have an application that uses EF 5 and a database-first context which maps all the tables in a SQL Server 2008 database. 我有一个使用EF 5和数据库优先上下文的应用程序,该上下文映射SQL Server 2008数据库中的所有表。 Some of those tables are not used by my application.
其中一些表未由我的应用程序使用。 If I change the structure of an unused table, will it break my existing EF code?
如果更改未使用表的结构,是否会破坏现有的EF代码?
I will update the .edmx
to match the changed table soon (and yes I'll look into a bounded context too). 我将尽快更新
.edmx
以匹配更改后的表(是的,我也将研究有界上下文)。 I'm just curious to know if I need to do so, even when the table is entirely unused by my application. 我只是想知道是否需要这样做,即使该表在我的应用程序中完全没有使用。
If you attempt to access the mismatched tables either by accessing it's DbSet<T>
query or by access a navigation property to a T
or ICollection<T>
you will get a runtime exception. 如果尝试通过访问
DbSet<T>
查询或访问T
或ICollection<T>
的导航属性来访问不匹配的表,则将获得运行时异常。 It will be some type of System.Data.EntityException
(probably a System.Data.MappingException
). 这将是某种类型的
System.Data.EntityException
(可能是System.Data.MappingException
)。 The same thing will happen if you attempt to access a table that no longer exists. 如果您尝试访问一个不再存在的表,将会发生同样的事情。
It should not cause any exceptions until you access the mismatched/missing table. 在您访问不匹配/丢失的表之前,它不会引起任何异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.