我在使用实体框架5的Windows窗体应用程序(.net 4.0)中遇到问题。
我有一个DbContext实例作为类字段,如下所示:
protected MascoteAquariumEF model = new MascoteAquariumEF("name=MascoteAquariumEF");
这是我的连接字符串:
<connectionStrings>
<add name="MascoteAquariumEF"
connectionString="metadata=res://*/MascoteAquariumDBContext.csdl|res://*/MascoteAquariumDBContext.ssdl|res://*/MascoteAquariumDBContext.msl;provider=System.Data.SqlClient;provider connection string='data source=vm_visual_stdo\sqlexpress2008;initial catalog=MascoteAquarium;integrated security=True;multipleactiveresultsets=True;App=EntityFramework'"
providerName="System.Data.EntityClient" />
</connectionStrings>
在设计师中我看到了这个错误: 表单没有真正设计....但运行项目确定(没有错误)
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
任何想法?
答案 0 :(得分:1)
尝试仅传递名称值:
protected MascoteAquariumEF model = new MascoteAquariumEF("MascoteAquariumEF");
另外我认为在实例化你的上下文之前检查设计器中的表单是否更好:
protected MascoteAquariumEF model;
public YourForm()
{
InitializeComponent();
if (DesignMode)
return; // you don't need to create context
model = new MascoteAquariumEF("MascoteAquariumEF");
}