为什么我的 Firebird 2.5.3 EntityFramework 6 Code First 项目中不断出现 "The type of the SQL statement could not be determined." 错误?

Why do I keep getting "The type of the SQL statement could not be determined." error in my Firebird 2.5.3 EntityFramework 6 Code First project?

我一直在搞一个使用 Firebird Entity Framework Provider 4.9.0、Firebird ADO.NET Data provider 4.9.0 和 EntityFramework 6.1.3 的代码优先项目Firebird 2.5.3 数据库服务器。这是 Git Repo .

我尽量让这个示例超级简单。我想指出的是,在我的示例中,从 post 中借用了一些关于 EntityValidationErrors 的代码,并且效果很好。

当示例为 运行 时生成数据库但返回此错误和堆栈跟踪:

System.ArgumentException was unhandled
  HResult=-2147024809
  Message=The type of the SQL statement could not be determined.
Statement: -- Tables

-- Foreign Key Constraints


-- EOF.
  Source=FirebirdSql.Data.FirebirdClient
  StackTrace:
       at FirebirdSql.Data.Isql.FbScript.Parse()
       at FirebirdSql.Data.EntityFramework6.FbProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) in C:\Users\Jiri\Documents\devel\NETProvider\working\NETProvider\src\FirebirdSql.Data.FirebirdClient\FirebirdClient\FbProviderServices.cs:line 417
       at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
       at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
       at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
       at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
       at System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func`3 createMigrator, ObjectContext objectContext)
       at System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState)
       at System.Data.Entity.Database.Create(DatabaseExistenceState existenceState)
       at System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context)
       at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf`1.<CreateInitializationAction>b__e()
       at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
       at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
       at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
       at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
       at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
       at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
       at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
       at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
       at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
       at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
       at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
       at System.Data.Entity.DbSet`1.Add(TEntity entity)
       at FirebirdEF6Test.Program.Main(String[] args) in C:\Users\Todd\Documents\VSTesting\FirebirdEF6Test\FirebirdEF6Test\Program.cs:line 19
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

我是实体框架的新手。但是在大多数教程中,我看到可以生成数据库和 table,而不必在代码中完全定义 table。 Firebird 不是这样吗?

感谢您的指导。祝你有美好的一天!

感谢@Mark Rotteveel 为我指明了正确的方向,感谢@Jiri Cincura 修复了错误。将我的测试项目升级到最新版本后:

EntityFramework.Firebird 4.10.0.0 & FirebirdSql.Data.FirebirdClient 4.10.0.0

项目按预期构建了数据库。这是很不错的。我已将 GitRepo 更新为工作示例。几个问题:我不确定是包管理器还是我,但是,首先我在 powershell 中遇到 "Set-ExecutionPolicy" 问题,包管理器不允许我使用 update-package。我收到有关该政策的错误信息。将策略更改为 "Unrestricted" 没有帮助。所以我右键单击该项目并尝试用那里的包管理器更新它们,它做到了。但遗憾的是,当我查看参考资料时,它们不见了。最终:

  • 我重启了VS2015
  • 已逐个删除每个包。
  • 重新启动
  • 已添加 EntityFramework.Firebird 4.10.0.0 返回。
  • 已将 FirebirdSql.Data.FirebirdClient 从 4.5.0.0(默认)更新到 4.10.0.0

我的经验告诉我,在使用包管理器时要小心,它并不总是像您期望的那样运行。还要确保你检查 app.config 它是否正确更新

  <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.10.0.0" newVersion="4.10.0.0" />
  </dependentAssembly>
</assemblyBinding>

祝你度过充实而充实的一天!