打开MainWindow.xaml时会调用EF 6 OnModelCreating

时间:2016-11-16 17:23:27

标签: c# wpf entity-framework-6 ef-database-first

我有一个使用Database First的Entity Framework 6.1.3应用程序。 应用程序正常运行,我从数据库中获取了我想要的数据。

问题是当我打开(双击)MainWindow.xaml时出现此错误

UnintentionalCodeFirstException: The context is being used in Code First 
mode with code that was generated from an EDMX file for either Database 
First or Model First development. This will not work correctly. To fix 
this problem do not remove the line of code that throws this exception. 
If you wish to use Database First or Model First, then make sure that 
the Entity Framework connection string is included in the app.config or 
web.config of the start-up project. If you are creating your own 
DbConnection, then make sure that it is an EntityConnection and not some 
other type of DbConnection, and that you pass it to one of the base 
DbContext constructors that take a DbConnection. To learn more about 
Code First, Database First, and Model First see the Entity Framework 
documentation here: http://go.microsoft.com/fwlink/?LinkId=394715 

所以EF正在调用 OnModelCreating(..) 它不应该!

来自app.config的连接字符串:

 <connectionStrings>
<add name="AuthorBookEntities" connectionString="metadata=res://*/AuthorBook.csdl|res://*/AuthorBook.ssdl|res://*/AuthorBook.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=LENOVO-PC;initial catalog=BOOKS;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

所有EF代码都是由T4脚本创建的。 该应用程序是一个WPF程序,没有dll或任何东西......

可能出现什么问题?

0 个答案:

没有答案
相关问题