2

I have been messing around with a code first project using the Firebird Entity Framework Provider 4.9.0, Firebird ADO.NET Data provider 4.9.0 and EntityFramework 6.1.3 with a Firebird 2.5.3 database server. Here is the Git Repo .

I have tried to keep this sample super simple. I want to point out that in my sample borrowed some code from a post about EntityValidationErrors and it work excellent.

When the sample is run the database is generated but this error and stacktrace are returned:

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: 

I am a novice to the Entitiy Framework. But in most of the tutorials I saw it was possible to generate the database and tables without having to completely define the table in code. Is this not the case with Firebird?

Thanks for any guidance. Have an amazing day!

Community
  • 1
  • 1
Todd
  • 119
  • 10
  • It looks like a script is generated with comments in it, and the Firebird .net provider `FbScript` script parser tries to execute a comment in isolation (without a real statement before or after it) and then fails because a comment isn't a valid statement. At first glance it looks like a bug. You might want to report it at http://tracker.firebirdsql.org/browse/DNET . – Mark Rotteveel Jan 07 '16 at 18:45
  • Thanks @MarkRotteveel I agree and as stupid as it sounds I had not considored it a bug. I have submitted it as you suggested. [DNET-664](http://tracker.firebirdsql.org/browse/DNET-664) When I dump the script out this is what I see: `-- Tables RECREATE TABLE "ACCOUNTs" ( "ID" VARCHAR(128) NOT NULL, "NAME" BLOB SUB_TYPE TEXT, CONSTRAINT "PK_ACCOUNTs" PRIMARY KEY ("ID") ); -- Foreign Key Constraints -- EOF` – Todd Jan 07 '16 at 19:21
  • @Todd Are u solved this problem already? Could you give me a solution because I have the same bug while using firebird with EntityFramework – whizzzkey Jan 17 '16 at 10:13
  • @whizzzkey I submitted the bug and it appeared as resolved. The new version 4.10.0.0 came out and I just got around to upgrading my project and retesting the code. Without diving into it to deep at the moment I would have to say it is not resolved and needs another look. But I want to be sure the issue is not on my side first. It might take a little bit before I can continue with it. – Todd Jan 18 '16 at 21:33
  • As an aside If you don't actually need to have it create the database you can have it display the script and use that to manually create the database and that has allowed me to continue on my project while this gets sorted out. `public static class CreateScript { public static string CreateDatabaseScript(this DbContext context) { return ((IObjectContextAdapter)context).ObjectContext.CreateDatabaseScript(); } }` – Todd Jan 18 '16 at 21:39
  • You can implement it something like this: `try { using (var db = new MyEntities()) { var script = CreateScript.CreateDatabaseScript(db); if (Directory.Exists(@"C:\Data")) { File.WriteAllText(@"C:\Data\script.sql", script); } db.ACCOUNTS.Add(new ACCOUNT { ID = "1", NAME = "Payable" }); db.SaveChanges(); Console.WriteLine(script); var a = Console.ReadLine(); } } catch { throw; }` – Todd Jan 18 '16 at 21:40

1 Answers1

2

I want to give credit to @Mark Rotteveel for pointing me in the right direction and @Jiri Cincura for fixing the bug. After upgrading my test project to the latest versions:

EntityFramework.Firebird 4.10.0.0 & FirebirdSql.Data.FirebirdClient 4.10.0.0

The project built the database as expected. Its very nice. I have updated the GitRepo to be a working sample. Couple of issues: I am not sure if it is the package manager or me, but, first I had issues with "Set-ExecutionPolicy" in powershell the package manager did not allow me to use update-package. I got a error about the policy. Changed the policy to "Unrestricted" did not help. So I right clicked the project and tried to update them with the package manager there and it did. But sadly when I looked at the references they were missing. Utimately:

  • I restarted VS2015
  • Removed each package 1 by 1.
  • Restarted again
  • Added EntityFramework.Firebird 4.10.0.0 back.
  • Updated FirebirdSql.Data.FirebirdClient from 4.5.0.0(default) to 4.10.0.0

All that to say be careful when using the package manager my experience has told me it does not always behave like you would expect. Also make sure that you check you app.config that it updated correctly

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

Have an amazing and fruitful day!

Todd
  • 119
  • 10