SQLite has a very limited support to alter tables. The recommended workaround is to create a new table with the altered columns and the copy the data from the old table to the newly created.
Question: is there any generic implementation available (c# using EF/Devart classes) so that no explicit SQL-statements must be written?
i.e. something like this:
Code: Select all
void AlterTable(string existingTableName, Type newTableEntity)
This method could use the both argument to create the statement.
By issuing the add-migration command Visual Studio generated the migration script. This file contains code that created the requested tables:
Code: Select all
CreateTable(
"dbo.Permission",
c => new
{
Id = c.NotNullableVarchar(32),
Name = c.String(nullable: false),
IsDeleted = c.Boolean(nullable: false),
})
.PrimaryKey(t => t.Id);
I suspect there are some helper methods in EF available to obtain metainfo of the columns for a table that is used by the add-migration tool to generate the script. In a similar way the above mentioned
AlterTable command could use the metainfo of a table to generate the column list for the
CreateTablemethod. Further also the primary keys, indices, ... could be created by analizing the metadata.