Entity framework 在主项目中共享子项目中的EF连接字符串
我有两个项目Entity framework 在主项目中共享子项目中的EF连接字符串,entity-framework,ef-code-first,Entity Framework,Ef Code First,我有两个项目 MyProject //MVC 3 app MyProject.DAL //Class Library project type 在MyProject.DAL内部有一个文件夹EntityModels,其中包含生成的实体(EF代码优先方法): app.config: <add name="myEntities" connectionString="metadata=res://*/EntityModels.DBMainModel.csdl|res://*/EntityMod
MyProject //MVC 3 app
MyProject.DAL //Class Library project type
在MyProject.DAL
内部有一个文件夹EntityModels
,其中包含生成的实体(EF代码优先方法):
app.config:
<add name="myEntities" connectionString="metadata=res://*/EntityModels.DBMainModel.csdl|res://*/EntityModels.DBMainModel.ssdl|res://*/EntityModels.DBMainModel.msl;provider=..." providerName="System.Data.EntityClient" />
但什么都不管用。如何修复它?如果首先是代码,则应在相应的.config文件中放入纯连接字符串值(您处理的是
SqlClient
而不是EntityClient
)。要了解有关ConnectionString值的更多信息,请查看 对于SQL Server数据库,基本上如下所示:
<add name="MyEntities" connectionString="Data Source=myServerName\myInstanceName;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;" providerName="System.Data.SqlClient"/>
<add name="myEntities"
connectionString="metadata=res://*/MyProject.DAL.EntityModels.DBMainModel.csdl|
res://*/MyProject.DAL.EntityModels.DBMainModel.ssdl|
res://*/MyProject.DAL.EntityModels.DBMainModel.msl;provider=..." providerName="System.Data.EntityClient" />
<add name="myEntities"
connectionString="metadata=res://MyProject.DAL.EntityModels.DBMainModel.csdl|
res://MyProject.DAL.EntityModels.DBMainModel.ssdl|
res://MyProject.DAL.EntityModels.DBMainModel.msl;provider=..." providerName="System.Data.EntityClient" />
<add name="myEntities"
connectionString="metadata=res://MyProject.DAL/EntityModels.DBMainModel.csdl|
res://MyProject.DAL/EntityModels.DBMainModel.ssdl|
res://MyProject.DAL/EntityModels.DBMainModel.msl;provider=..." providerName="System.Data.EntityClient" />
<add name="MyEntities" connectionString="Data Source=myServerName\myInstanceName;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;" providerName="System.Data.SqlClient"/>