创建实体实例。 (连接字符串)
我在尝试使用实体框架连接到数据库时遇到问题。我真的不知道如何解释,所以我发布了一些代码。我想创建 dbEntities 的实例并使用它连接到我的数据库,在第二部分中您可以看到我的连接字符串。当我尝试运行此程序时,出现以下错误;
XampParseException 未处理:
构造函数的调用 输入匹配的“test.MainWindow” 指定的绑定约束 抛出异常。行号“3” 和行位置“9”。
还有内心的例外……
混合模式程序集是针对运行时版本“v2.0.50727”构建的,如果没有附加配置信息,则无法在 4.0 运行时中加载。":nul。
我到达了 public dbEntities() : base(....) 行,但是我希望有人能告诉我该怎么做
。
public class LinqConnection
{
private readonly dbEntities _linq;
private static LinqConnection _instance;
private LinqConnection()
{
_linq = new dbEntities();
}
public static dbEntities Instance
{
get
{
if (_instance == null)
_instance = new LinqConnection();
return _instance._linq;
}
}
}
public dbEntities()
: base("metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite;provider connection string=';data source=db.db3;Password=testpass';", "dbEntities")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
I have a problem when trying to use Entity framework to connect to my database. I dont really know how to explain so I post some code. I want to make an instance of dbEntities and use it to connect to my DB, in the second section you can see my connection string. I get the following error when I try to run this;
XampParseException was unhandled:
The invocation of the constructor on
type 'test.MainWindow' that matches
the specified binding constraints
threw an exception.' Line number '3'
and line position '9'.
And a inner exeption...
Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.":nul.
I get to the line public dbEntities() : base(....) but there it crashes. I hope some one could give me a hint what to do.
/Nick
public class LinqConnection
{
private readonly dbEntities _linq;
private static LinqConnection _instance;
private LinqConnection()
{
_linq = new dbEntities();
}
public static dbEntities Instance
{
get
{
if (_instance == null)
_instance = new LinqConnection();
return _instance._linq;
}
}
}
public dbEntities()
: base("metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite;provider connection string=';data source=db.db3;Password=testpass';", "dbEntities")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您对 SQLite + .NET 4.0 有问题 - 检查 这个问题。它与实体框架或连接字符串无关。
Looks like you have a problem with SQLite + .NET 4.0 - check this question. It is not related to Entity framework or connection string.