gpt4 book ai didi

c# - Interbase XE7 和 Entity Framework 6.1.2

转载 作者:太空狗 更新时间:2023-10-30 01:18:15 25 4
gpt4 key购买 nike

目前我正在做一个项目,我想使用 Entity Framework 为 Interbase 数据库创建一个数据库层。唯一的问题是我无法让它工作,所以我求助于我亲爱的 SO 共同用户。

我目前正在使用:

  • Visual Studio 2013 高级版

  • Interbase XE7 开发者版(download here)

  • Entity Framework 6.1.2

  • Interbase ADO.NET 驱动程序随 Interbase XE7 安装提供

对于这个例子,我创建了一个非常简单的数据库,只有 1 个表 UserTypes其中包含 ID和一个 Description .

我编写了以下代码来表示我的 UserTypes模型和我的上下文(这确实非常基础):

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; }
}

在我的 Main 内我编写了以下代码:

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();
}

不过,当我运行应用程序时 ProviderIncompatibleException在执行 LINQ 查询时抛出。异常具有以下消息:

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.

我对异常的解释是Embarcadero提供的provider不提供对Entity Framework的支持。所以我的问题如下:

  • Interbase ADO.NET 驱动程序是否提供对 Entity Framework 的支持?还是我做错了什么?

  • 是否可能有任何其他驱动程序支持我所需的功能?

非常感谢有关此主题的任何帮助。

我在使用成功运行的 Microsoft SQL Server 数据库时也尝试了相同的代码,因此我认为我的代码通常没有任何问题。

最佳答案

据我所知,EF不支持连接Interbase数据库。但是,应该可以根据 EF 的指南编写您自己的提供程序,该指南可在 here 中找到。 .

首先,您可能想看看 FireBird 提供程序(它是开源的)并且已经在使用 EF。如果您研究提供的代码,您可能会很好地触发为 EF 编写您自己的 Interbase 提供程序。可以找到指向 FireBirds EF .NET Provider 的链接 here

关于c# - Interbase XE7 和 Entity Framework 6.1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28106283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com