适用于 mySQL 实体类的实体框架
我有这样的配置:
<connectionStrings>
<!--<add name="NREticaretContext"
connectionString="Data Source=localhost;Initial Catalog=myDBSqlServer;Persist Security Info=True;User ID=sa;Password=mypass;Timeout=20;"
providerName="System.Data.SqlClient" />-->
<add name="NREticaretContext"
connectionString="Server=localhost;Database=myDBMySQL;Uid=root;Pwd=mypass;port=3306;" providerName="MySql.Data.MySqlClient"/>
如果我使用第一个配置设置(SQL Server),则一切都在我的项目中正常工作。 但是,当我尝试对使用 mySQL 实体框架的 mySQL 连接器使用第二个连接(mySQL)时,应用程序不断提示:
“无法检查模型兼容性,因为模型中未包含 EdmMetadata 类型。请确保 IncludeMetadataConvention 已添加到DbModelBuilder 约定。”
我尝试过
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
}
在我的 Context 类中使用 : 但它不断给出相同的错误...... 你的建议?
I have this configuration:
<connectionStrings>
<!--<add name="NREticaretContext"
connectionString="Data Source=localhost;Initial Catalog=myDBSqlServer;Persist Security Info=True;User ID=sa;Password=mypass;Timeout=20;"
providerName="System.Data.SqlClient" />-->
<add name="NREticaretContext"
connectionString="Server=localhost;Database=myDBMySQL;Uid=root;Pwd=mypass;port=3306;" providerName="MySql.Data.MySqlClient"/>
if I use first config setting(SQL Server) everythicg works fine in my project.
But when I try to use second connection(mySQL) for mySQL connector which uses mySQL Entity Framework, application keeps on saying:
"Model compatibility cannot be checked because the EdmMetadata type was not included in the model. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions."
I have tried using :
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
}
in my Context class but it keeps on giving the same error...
Your suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前,Connector /NET 似乎在使用 EF 4.1 时遇到了一些问题。
尝试关闭初始化策略
System.Data.Entity.Database.SetInitializer(null);
我建议您查看 我们博客上的代码优先支持文章。它描述了 dotConnect for MySQL 中使用 Code First 的一些特性。
It seems that Connector /NET experiences some problems with EF 4.1 at the moment.
Try turning off the Initialization Strategy
System.Data.Entity.Database.SetInitializer<MyContext>(null);
I recommend you to take a look at the Code First Support article at our blog. It describes some peculiarities of working with Code First in dotConnect for MySQL.