generate CreateTableOperation instance

Usa Pop 1 Reputation point
2021-02-23T08:06:18.36+00:00

I want to create new instance of CreateTableOperation class from my model via reflection or enything else. I have my model's name and I want to access CreateTableOperation instance with all ef standard attribute, to use it can anyone help me?

my domain classes:

public class A
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int Id { get; set; }
        public int Value { get; set; }
    }
    public class A_1
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int Id { get; set; }
        public int Value { get; set; }
    }
    public class A_2
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int Id { get; set; }
        public int Value { get; set; }
    }

my sqlGenerator class:

public class MyMigrationSqLGenerator : MigrationSqlGenerator
    {
        private string GenerateSqlStatement(AddColumnOperation migrationOperation)
        {
         //Now, I have name of table from migrationOperation.Table. like A,
         //and I want to create table A_1 or A_2 and generate create command,
         //I need something like CreateTableOperation to give me A_1 or A_2 columns and annotations
    }
    }
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,423 questions
SQL Server Migration Assistant
SQL Server Migration Assistant
A Microsoft tool designed to automate database migration to SQL Server from Access, DB2, MySQL, Oracle, and SAP ASE.
496 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,320 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,621 Reputation points
    2021-02-25T06:05:14.003+00:00

    Hi UsaPop-1381,
    The CreateTableOperation class represents creating a table.
    And as document said, Entity Framework Migrations APIs are not designed to accept input provided by untrusted sources (such as the end user of an application).
    If input is accepted from such sources it should be validated before being passed to these APIs to protect against SQL injection attacks etc.
    For custom migrations, you can define custom MigrationOperation objects.
    Here are some related links:
    Custom Migrations Operations
    How to customize migration generation in EF Core Code First?
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.