简体   繁体   中英

Interbase XE7 and Entity Framework 6.1.2

Currently I am working on a project where I want to create a database layer for Interbase database using the Entity Framework. The only thing is that I can't get it to work, so I turn to my beloved SO co-users.

I am currently using:

  • Visual Studio 2013 Premium

  • Interbase XE7 Developer Edition ( download here )

  • Entity Framework 6.1.2

  • Interbase ADO.NET driver provided with Interbase XE7 installation

For this example I've created a very simple database with only 1 table UserTypes which contains an ID and a Description .

I've written the following code to represent my UserTypes model and my context (which is indeed very basic):

public class MyContext : DbContext
{
    public MyContext(DbConnection connection)
        : base(connection, true)
    { }

    public virtual DbSet<UserTypes> UserTypes { get; set; }
}

public class UserTypes
{
    [Key]
    public int ID { get; set; }

    [StringLength(40)]
    public string Description { get; set; }
}

Within my Main I've authored the following code:

static void Main(string[] args)
{
    TAdoDbxConnectionStringBuilder CnStrBuilder = new TAdoDbxConnectionStringBuilder()
    {
        User_Name = "SYSDBA",
        Password = "masterkey",
        DBHostName = "localhost",
        Database = @"C:\Users.gdb",
        DriverName = "Interbase"
    };

    DbConnection connection = new TAdoDbxInterBaseConnection();
    connection.ConnectionString = CnStrBuilder.ConnectionString;

    using (var context = new MyContext(connection))
    {
        Console.WriteLine("Showing all user types");

        var query = from ut in context.UserTypes
                    orderby ut.ID
                    select ut;

        foreach (var userType in query)
        {
            Console.WriteLine("{0}: {1}", userType.ID, userType.Description);
        }
    }

    Console.WriteLine("Press any key to exit...");
    Console.ReadKey();
}

Though, when I run the application a ProviderIncompatibleException is thrown when executing the LINQ query. The exception has the following message:

A null was returned after calling the 'get_ProviderFactory' method on a store provider instance of type 'Borland.Data.TAdoDbxInterBaseConnection'. The store provider might not be functioning correctly.

My interpretation of the exception is that the provider provided by Embarcadero does not provide support for the Entity Framework. So the questions I have are the following:

  • Does the Interbase ADO.NET driver provide support for the Entity Framework? Or am I doing something wrong?

  • Is there perhaps any other driver that supports my desired functionality?

Any help on this topic would be highly appreciated.

I've also tried the same code whilst using a Microsoft SQL Server database which worked successfully so I don't think there is anything wrong my code generally.

As far as I currently know, there is no support for connecting Interbase database with EF. However, it should be possible to write your own provider based upon the guidelines from EF which can be found here .

To get started, you might want to have a look at the FireBird provider (which is open source) and is already working with EF. If you study the provided code, you might have a good trigger to write your own Interbase provider for EF. The link to FireBirds EF .NET Provider can be found here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM