问题
As EF Migration do provide a way to create new columns as part of migration like below
public class AddRatingMig : DbMigration
{
public override void Up()
{
AddColumn("dbo.Movies", "Rating", c => c.String());
}
public override void Down()
{
DropColumn("dbo.Movies", "Rating");
}
}
But I want to create a column as part of code and not thru migration. We are providing admins an option to capture more information about the users of the application. The facility to do that will be thru some checkboxes on front end. On the basis of that, columns will be added on backend.
So what I am looking at is, an injectionor for migration-implementor, using which i can call the "AddColumn" method. I can hardcode it, but given that EF-migration
or fluent-migrator
does that using a fluent syntax, was checking if I could use it.
public interface IDbManagerService {
void AddColumn(string table, string column)
}
public class DbManager: IDbManagerService {
private readonly ??? dbMigrator;
void AddColumn(string table, string column) {
dbMigrator.AddColumn(table, column)
}
}
来源:https://stackoverflow.com/questions/58966669/add-new-column-to-database-table-dynamically