0

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();
    }
Community
  • 1
  • 1
Nick3
  • 639
  • 1
  • 14
  • 40
  • This looks like it's unrelated to EF - are you using a .NET 2 assembly within a .NET 4 project? What other dependencies does your project have? – BrokenGlass Mar 31 '11 at 20:38

1 Answers1

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.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670