我必须使用 Firebird 嵌入式数据库和实体框架。我已经下载了连接器,如果我使用此代码:
using FirebirdSql.Data.FirebirdClient;
[...]
string exePath = Path.GetDirectoryName(
new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
FbConnectionStringBuilder fbStringBuilder = new FbConnectionStringBuilder();
fbStringBuilder.ServerType = FbServerType.Embedded;
fbStringBuilder.UserID = "SYSDBA";
fbStringBuilder.Password = "MASTERKEY";
fbStringBuilder.Dialect = 3;
fbStringBuilder.Charset = "UTF8";
fbStringBuilder.ClientLibrary = Path.Combine(exePath, "fbembed.dll");
fbStringBuilder.Database = Path.Combine(exePath, "test.fdb");
if (!File.Exists(Path.Combine(exePath, "test.fdb")))
{
FbConnection.CreateDatabase(fbStringBuilder.ToString());
}
FbConnection fbConn = new FbConnection(fbStringBuilder.ToString());
try
{
fbConn.Open();
Console.WriteLine("OK");
}
catch (Exception ex)
{
Console.WriteLine("ERROR");
Console.WriteLine(ex.Message);
Console.ReadKey();
}
finally
{
fbConn.Close();
}
一切正常。但是当我尝试将该连接字符串与 DbContext 一起使用时:
public class FirebirdEmbededExampleDbContext : DbContext
{
public FirebirdEmbededExampleDbContext(string connString) : base(connString)
{
this.Database.Connection.ConnectionString = connString;
}
public DbSet<ItemA> ItemsA { get; set; }
public DbSet<ItemB> ItemsB { get; set; }
}
它失败并显示消息:
Unsupported keyword: 'server type'
看来 EF 没有使用 Firebird 提供程序。我应该如何使用它?