【发布时间】:2014-01-06 21:18:35
【问题描述】:
我正在使用带有代码的嵌入式 Firebird 数据库(实体框架 6)。应用程序第一次运行时,它运行良好:创建数据库并插入数据。但之后每次运行时,都会抛出以下异常:
“System.NotSupportedException”类型的异常发生在 FirebirdSql.Data.FirebirdClient.dll 但未在用户代码中处理
附加信息:未知数据类型
该项目包括以下 NuGet 包:
- EntityFramework [6.0.2]
- Firebird ADO.NET 数据提供程序(实体框架 6)[4.1.0.0]
如here 所述,我将DbProviderFactories 和FirebirdSql.Data.FirebirdClient 提供程序添加到App.config。
我还将 Firebird DLL 添加到项目中并将它们设置为复制到输出目录:
- fbembed.dll
- ib_util.dll
- icudt30.dll
- icuin30.dll
- icuuc30.dll
我还没有 enabled 代码优先迁移(尽管__MigrationHistory 表仍因某种原因被创建)。
代码如下:
class Program
{
static void Main(string[] args)
{
Database.SetInitializer<FirebirdDbContext>(new CreateDatabaseIfNotExists<FirebirdDbContext>());
string connectionString = "server type=Embedded;user id=sysdba;password=masterkey;role name=RDB$ADMIN;character set=UTF8;initial catalog=test.fdb";
using (var context = new FirebirdDbContext(connectionString))
{
context.Users.Add(new User()
{ Created = DateTime.Now,
Name = "smith" });
context.SaveChanges();
}
}
}
class User
{
[Key]
public DateTime Created { get; set; }
public string Name { get; set; }
}
class FirebirdDbContext : DbContext
{
public FirebirdDbContext(string connString)
: base(new FbConnection(connString), true) { }
public DbSet<User> Users { get; set; }
}
class MyConfiguration : DbConfiguration
{
public MyConfiguration()
{
SetDefaultHistoryContext((c, s) => new SmallKeyHistoryContext(c, s));
}
}
class SmallKeyHistoryContext : HistoryContext
{
public SmallKeyHistoryContext(DbConnection existingConnection, string defaultSchema)
: base(existingConnection, defaultSchema) { }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// HACK: Make this column smaller to avoid the following error:
// key size exceeds implementation restriction for index "PK___MigrationHistory"
modelBuilder.Entity<HistoryRow>().Property(h => h.ContextKey).HasMaxLength(53).IsRequired();
}
}
在context.Users.Add(...) 行引发异常。
这是堆栈跟踪:
at FirebirdSql.Data.Common.DbValue.GetBytes() in c:\Users\Jiri\Documents\devel\NETProvider\working\NETProvider\source\FirebirdSql\Data\Common\DbValue.cs:line 315
at FirebirdSql.Data.Client.Common.XsqldaMarshaler.MarshalManagedToNative(Charset charset, Descriptor descriptor) in c:\Users\Jiri\Documents\devel\NETProvider\working\NETProvider\source\FirebirdSql\Data\Client\Common\XsqldaMarshaler.cs:line 121
at FirebirdSql.Data.Client.Native.FesStatement.Execute() in c:\Users\Jiri\Documents\devel\NETProvider\working\NETProvider\source\FirebirdSql\Data\Client\Native\FesStatement.cs:line 355
at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteCommand(CommandBehavior behavior, Boolean returnsSet) in c:\Users\Jiri\Documents\devel\NETProvider\working\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbCommand.cs:line 1246
at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteReader(CommandBehavior behavior) in c:\Users\Jiri\Documents\devel\NETProvider\working\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbCommand.cs:line 566
at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteDbDataReader(CommandBehavior behavior) in c:\Users\Jiri\Documents\devel\NETProvider\working\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbCommand.cs:line 666
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<>c__DisplayClassb.<Reader>b__8()
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TInterceptionContext,TResult](Func`1 operation, TInterceptionContext interceptionContext, Action`1 executing, Action`1 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
堆栈跟踪指向 Firebird 库 (right here)。我尝试向后跟踪代码,但我不知道是为所有字段调用GetBytes() 还是只为byte[] 字段调用。 (我一开始以为可能和数据库中的__MigrationHistory.Model字段有关,但是如果那个表是空的,还是会报错。不过,我不希望我的推测造成误导。)
我可以解决这个问题,但我真的很想了解它。有谁知道这里发生了什么?
【问题讨论】:
-
能否包含异常的堆栈跟踪?
-
@MarkRotteveel 我在帖子中添加了堆栈跟踪和一些其他信息。
标签: c# ef-code-first firebird entity-framework-6 firebird-embedded