MicroLite-ORM / MicroLite

MicroLite ORM framework
microliteorm.wordpress.com
Apache License 2.0
85 stars 24 forks source link

"Invalid data type:26" on Insert with Firebird DB 3 #468

Closed oschwab closed 7 years ago

oschwab commented 7 years ago

Hello,

I'm evaluating using Microlite with Firebird database in version 3. I'm stuck on the following problem: Executing session.Insert triggers the exception: image I logged Microlite output but all seems OK , mapping included :

https://gist.github.com/oschwab/66c7a740ca8ff6b80502c5b6f1d7a3d7#file-gistfile1-txt

I had a quick look to Microlite code, and found no path from where this message is triggered. Nothing on Firebird side too.

Thanks by advance for help.

TrevorPilley commented 7 years ago

Hi, are you looking at the 3.2.x branch?

TrevorPilley commented 7 years ago

6.3.x even!

oschwab commented 7 years ago

Yes sorry for forgetting this precision, I use Microlite 6.3.0.0 (last from nuget)

TrevorPilley commented 7 years ago

The actual exception text will be from the database itself, are the property types in your object compatible with the column types in the table?

oschwab commented 7 years ago

As Fetch< > works, I bet this is because of DbGenerated ID. I used a sequence and trigger as explained in Firebird Docs

ID Column seems correctly detected by mapping though. And log files (Microlite or Firebird) don't show any query.

TrevorPilley commented 7 years ago

Can you paste the full stack trace?

oschwab commented 7 years ago

Of course !

MicroLite.MicroLiteException was unhandled HResult=-2146233088 Message=Invalid data type: 26. Source=MicroLite StackTrace: at MicroLite.Core.Session.ExecuteScalarQuery[T](SqlQuery sqlQuery) at MicroLite.Core.Session.InsertReturningIdentifier(IObjectInfo objectInfo, Object instance) at MicroLite.Core.Session.Insert(Object instance) at MicroliteEval.Repository.Database.DBRepository`1.Insert(T obj) in C:\Users\Olivier Schwab\Documents\Diasys\Development\dt-soft\proto\MicroliteEval\MicroliteEval\Repository\Database\DBRepository.cs:line 60 at MicroliteEval.Program.Main(String[] args) in C:\Users\Olivier Schwab\Documents\Diasys\Development\dt-soft\proto\MicroliteEval\MicroliteEval\Program.cs:line 55 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: HResult=-2147024809 Message=Invalid data type: 26. Source=FirebirdSql.Data.FirebirdClient StackTrace: at FirebirdSql.Data.Common.TypeHelper.GetDbDataTypeFromDbType(DbType type) at FirebirdSql.Data.FirebirdClient.FbParameter.set_DbType(DbType value) at MicroLite.Driver.DbDriver.BuildParameter(IDbDataParameter parameter, String parameterName, SqlArgument sqlArgument) at MicroLite.Driver.DbDriver.BuildCommand(IDbCommand command, SqlQuery sqlQuery) at MicroLite.Core.SessionBase.ConfigureCommand(SqlQuery sqlQuery) at MicroLite.Core.Session.ExecuteScalarQuery[T](SqlQuery sqlQuery) InnerException:

TrevorPilley commented 7 years ago

This looks to be where the exception comes from

FirebirdSql.Data.Common.TypeHelper.GetDbDataTypeFromDbType(DbType type)

oschwab commented 7 years ago

If I understand correctly, during the query construction, Microlite asks to FB provider a mapping for a type , and the provider complains about it ?

TrevorPilley commented 7 years ago

It's when MicroLite sets the value for a parameter.

It could be related to the enum, do you have any constraints on that column & a mismatch between the enum values and what's in the db?

oschwab commented 7 years ago

Unfortunately, same error message with an entity without enum. Two other points :

oschwab commented 7 years ago

The problems comes from DbType.DateTime2 (= 26). Trying to investigate deeper.

TrevorPilley commented 7 years ago

Ah OK, the default mapping for System.DateTime in MicroLite 6.3+ is DbType.DateTime2, however if Firebird doesn't support DbType.DateTime2 then you will need to override that . See the DateTime mapping section of Upgrading to MicroLite 6.3 as that explains how to alter the default mappings.

oschwab commented 7 years ago

Cristal clear ! My test project is working perfectly now. I must now perform some benchmarks . Maybe this information should be added in using Firebird page ? I have some other questions (mainly regarding managing 1-1 and 1-many relationships) but I'll create another issue for it. This issue can be closed, thank you very much for your quick help.

TrevorPilley commented 7 years ago

I'll update the page - to be honest I haven't used Firebird since I did the original MicroLite implementation so I wasn't aware that it didn't support DbType.DateTime2 until 30 mins ago when you dug into your problem.

oschwab commented 7 years ago

To be honest on my side, Firebird is an obligation, not a real choice ....