WebApi中使用EF一些报错及解决

 

System.InvalidOperationException:“No connection string named 'con' could be found in the application config file.”
翻译:
System.InvalidOperationException:“在应用程序配置文件中找不到名为‘con’的连接字符串。”

在WebApi项目中加上数据库连接字符串

 

System.Data.Entity.Core.MetadataException:“Unable to load the specified metadata resource.”
翻译
System.Data.Entity.Core.MetadataException:“无法加载指定的元数据资源。”

 这个是App.Config或者Web.config中的连接字符串有问题,

<add name="AuthorizeContainer" connectionString="metadata=res://*/Models.Authorize.csdl|res://*/Models.Authorize.ssdl|res://*/Models.Authorize.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=Server;Initial Catalog=EIPS;Persist Security Info=True;User ID=sa;Password=123;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

“metadata=res://*/Models.Authorize.csdl|res://*/Models.Authorize.ssdl|res://*/Models.Authorize.msl;”

我的这部分是从其他地方拷过来的,这个和edmx中的不一样就产生这个报错

 

System.Data.Entity.Core.MetadataException:“Schema specified is not valid. Errors: 
Model1.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.”

翻译:
System.Data.Entity.Core.MetadataException:“指定的架构无效。错误:

Model1.ssdl(2,2):错误0152:未找到具有不变名称“System.Data.SqlClient”的ADO.NET提供程序的实体框架提供程序。确保提供程序已在应用程序配置文件的“entityFramework”部分注册。看见http://go.microsoft.com/fwlink/?LinkId=260882 了解更多信息。”

这个是因为我的WebApi项目没有引用EF(下面这两个dll)

EntityFramework.dll

EntityFramework.SqlServer.dll

posted @ 2021-08-12 19:23  何以平天下  阅读(451)  评论(1编辑  收藏  举报