Import not possible when there's a Timestamp|RowVersion field
nstohler opened this issue · 15 comments
One of my EF Core was set up to have a concurrency token as described in
https://docs.microsoft.com/en-us/ef/core/modeling/concurrency#timestamprow-version
With the following field present, dbtool export ...
was able to export the table contents into a JSON file.
[Timestamp]
public byte[] RowVersion { get; set; }
But dbtool import ...
was then unable to create the records in the same DB (which I've previously deleted). It does not output any error message either, which made it quite hard to track down what exactly prevented the import.
When I manually remove the RowVersion entry in the "data" section of every record in the JSON, the import succeeds.
Thanks for the report. We will find out the reason of this error and fix it in the next update.
Version 1.1.5 is published.
Thanks
I've just tried it, but it did't work.
- I've updated with
dotnet tool update -g Korzh.DbTool
- exported data from the db with dbtool
- cleared some tables in LinqPad
- imported data with dbtool
Result:
Normal tables work as expected, but those with a RowVersion did not.
When I manually removed all the "RowVersion" lines of the data records, the import works.
Version 1.1.6 is published.
I've updated to 1.1.6, but now I'm getting the following when trying to import:
$ dbtool import -i:./demo/ blazor-boilerplate
Openning blazor-boilerplate connection...
Importing data to [blazor-boilerplate]...
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Korzh.DbUtils.BaseDbBridge.GetTableFullName(DatasetInfo table) in d:\a\1\s\src\Korzh.DbUtils\DbBridge\BaseDbBridge.cs:line 358
at Korzh.DbUtils.SqlServer.SqlServerBridge.TurnOnConstraints() in d:\a\1\s\src\Korzh.DbUtils.SqlServer\SqlServerBridge.cs:line 165
at Korzh.DbUtils.BaseDbBridge.FinishSeeding() in d:\a\1\s\src\Korzh.DbUtils\DbBridge\BaseDbBridge.cs:line 343
at Korzh.DbUtils.Import.DbImporter.Import() in d:\a\1\s\src\Korzh.DbUtils.Import\DbImporter.cs:line 57
at Korzh.DbTool.ImportCommand.Run() in d:\a\1\s\src\Korzh.DbTool\Commands\ImportCommand.cs:line 201
at Korzh.DbTool.Program.Main(String[] args) in d:\a\1\s\src\Korzh.DbTool\Program.cs:line 27
Segmentation fault
That's really strange because that line contains only var result = ""
assignment.
That's really strange because that line contains only
var result = ""
assignment.
I agree.
I might have time later today or tomorrow to compile dbtool on my machine and run it through the debugger.
I guess I know a possible reason of the problem. Will publish an update in a few minutes.
Debugging it too, found some other problem
I had to patch in the Database schema name to make it work on my database. Otherwise there was an error about not finding/accessing the table.
There was some inconsistency in Import method - it called FinishSeeding without StartSeeding if the imported file is empty. I have fixed this and will publish an update in 5 minutes.
Please include the schema fix as well!
https://github.com/kedonec/Korzh.DbUtils/blob/873110a9b560af9b4a359a5040b23cb20a818b76/src/Korzh.DbUtils/DbBridge/BaseDbBridge.cs#L356
GetTableFullName will return the wrong database tablename in case there's a db schema name!
My quick fix above works, but I guess it can be done cleaner.
OK. I've stopped the release and included your fix for Schema. The update is building now and will be published soon.
Done. Version 1.1.7 has been published and is validated on NuGet now. Will be listed in a few minutes.