[FB-Tracker] Created: (DNET-1003) Code First: Error seeding data when Table is created in same migration.

4 views
Skip to first unread message

Giacomo Policicchio (JIRA)

unread,
Jan 11, 2021, 4:12:55 AM1/11/21
to firebird-n...@googlegroups.com
Code First: Error seeding data when Table is created in same migration.
-----------------------------------------------------------------------

Key: DNET-1003
URL: http://tracker.firebirdsql.org/browse/DNET-1003
Project: .NET Data provider
Issue Type: Bug
Components: Entity Framework Core
Affects Versions: 7.10.1.0
Reporter: Giacomo Policicchio
Assignee: Jiri Cincura
Priority: Minor


Due to Firebird behavior, in same transaction is not possible to insert data in a newly created Table. So, using Entity.HasData in OnModelCreating in same Migration where the table is created, an error is raised and migration fails.
Scripting the migration instead of applying it with update-database confirms my supects, the structure is:

START TRANSACTION;
DDL statements
HasData DML statements
Insert into 'MigrationsHistoryTable'
COMMIT;

First solution that came to my mind reading the code could be to wrap relevant DDL statemens between "set autoddl on;" and "set audoddl off" statements, e.g. in "Migrations/FbMigrationsSqlGenerator,cs", method "Generate(CreateTableOperation....", it would be easy to add these statements, maybe adding a flag in FbOptionsExtension to preserve default original behavior.
But this solution is too dirty, because if for any reason migration fails, DDL command are executed partially needing to manually recover, if possible, prior database state. So the ideal solution instead would be to inject a "commit" and a "start transaction" between ddl and dml commands, so the only risks will be related to DML failing for any reason, but a fail like that could easily recovered. For this soultion I've to study more EF Core internal processes.
What do you thinK?

Bye







--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://tracker.firebirdsql.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply all
Reply to author
Forward
0 new messages