it:ad:code_first:migrations:howto:coded_migration_examples:createtable

IT:AD:EF/CodeFirst/Migrations:HowTo:Coded Migration Examples/CreateTable

            CreateTable(
                "dbo.Provider",
                c => new
                    {
                        ProviderId = c.Int(nullable: false, identity: true),
                        ProviderCode = c.String(nullable: false, maxLength: 10),
                        ProviderName = c.String(nullable: false, maxLength: 200),
                        GoliveDateTime = c.DateTime(),
                        FileFormatId = c.Int(nullable: false),
                        ShortName = c.String(maxLength: 20),
                        NeedsMmiApproval = c.Boolean(nullable: false),
                        InterfaceXml = c.Boolean(nullable: false),
                        InterfaceSoap = c.Boolean(nullable: false),
                        InterfaceBatch = c.Boolean(nullable: false),
                        OnBehalf = c.Boolean(nullable: false),
                        ActiveDurationDays = c.Int(nullable: false),
                        ManualMergeRequired = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.ProviderId)
                .ForeignKey("dbo.Reference_FileFormat", t => t.FileFormatId)
                .Index(t => t.FileFormatId);
                

bool exists = context.Database
                     .SqlQuery<int?>(@"
                         SELECT 1 FROM sys.tables AS T
                         INNER JOIN sys.schemas AS S ON T.schema_id = S.schema_id
                         WHERE S.Name = 'SchemaName' AND T.Name = 'TableName'")
                     .SingleOrDefault() != null;

  • /home/skysigal/public_html/data/pages/it/ad/code_first/migrations/howto/coded_migration_examples/createtable.txt
  • Last modified: 2023/11/04 02:45
  • by 127.0.0.1