I have a SQLite database (for my integration tests). All the mapping is inferred from the EF Core mapping (no manual configuration/attributes).
When I use BulkCopy with BulkCopyOptions using UseParameters = true, a DateTime value gets written as an empty string to the SQLite database, although the DateTime value is set to a valid, non-default value.
GetMaxLength() returns indeed null, fallback of 0 is used.
As far as I tested, only SQLite is affected (SQL Server and Oracle look to work fine).
Debugging
Used the debug symbols and debugged it. At the mentioned line I set the value of length to null instead of 0.
This fixed the issue for me in this debug run.
Theory
It seems for SQLite, this fallback causes Linq2db to not send anything. I guess, because in SQLite there is no DateTime type but it is represented (in my case) as TEXT, it trims the "text" to a length/size of 0 (fallback value). This leads to an empty string.
Expected
DateTime column value should not be cut down to an empty string but have a full date-time value.
Workaround
None that worked. Using UseParameters = false in BulkCopyOptions works for SQLite, but is inefficient in the real provider (Oracle).
I think in some way I can workaround it in the non-test implementation, but then the tests change the "unsuspecting" domain implementation which I dislike. So a fix would be appreciated.
Failed tries:
[Column(Length=50)] on property (ignored and without effect due to code mentioned above)
.HasMaxLength(50) in EF Core mapping (EF Core validation exception)
Issue
I have a SQLite database (for my integration tests). All the mapping is inferred from the EF Core mapping (no manual configuration/attributes).
When I use
BulkCopy
withBulkCopyOptions
usingUseParameters = true
, aDateTime
value gets written as an empty string to the SQLite database, although theDateTime
value is set to a valid, non-default value.Investigation
I debugged this and traced it back to this line https://github.com/linq2db/linq2db.EntityFrameworkCore/blob/44de54e460309d3790a8eba8fc3375276201c93f/Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs#L297
GetMaxLength()
returns indeednull
, fallback of0
is used.As far as I tested, only SQLite is affected (SQL Server and Oracle look to work fine).
Debugging
Used the debug symbols and debugged it. At the mentioned line I set the value of length to
null
instead of0
. This fixed the issue for me in this debug run.Theory
It seems for SQLite, this fallback causes Linq2db to not send anything. I guess, because in SQLite there is no
DateTime
type but it is represented (in my case) asTEXT
, it trims the "text" to a length/size of0
(fallback value). This leads to an empty string.Expected
DateTime
column value should not be cut down to an empty string but have a full date-time value.Workaround
None that worked.UsingUseParameters = false
inBulkCopyOptions
works for SQLite, but is inefficient in the real provider (Oracle). I think in some way I can workaround it in the non-test implementation, but then the tests change the "unsuspecting" domain implementation which I dislike. So a fix would be appreciated.Failed tries:
[Column(Length=50)]
on property (ignored and without effect due to code mentioned above).HasMaxLength(50)
in EF Core mapping (EF Core validation exception)Info
.NET: 7.10 linq2db: 5.2.2 linq2db.EntityFramework: 7.5.0