创建Audit.Net CodeFirst迁移事件模型

时间:2019-02-22 10:24:31

标签: c# entity-framework ef-code-first audit.net

我无法从官方sql查询中创建确切的模型作为模型来运行确切的迁移并创建具有确切属性的表。

    CREATE TABLE [Event]
(
    [EventId] BIGINT IDENTITY(1,1) NOT NULL,
    [InsertedDate] DATETIME NOT NULL DEFAULT(GETUTCDATE()),
    [LastUpdatedDate] DATETIME NULL,
    [Data] NVARCHAR(MAX) NOT NULL,
    CONSTRAINT PK_Event PRIMARY KEY (EventId)
)
GO

但是似乎我无法先用代码创建确切的表。

public partial class AddEventTable : DbMigration
{
    public override void Up()
    {
        CreateTable(
            "dbo.Event",
            c => new
                {
                    EventId = c.Long(nullable: false, identity: true),
                    Data = c.String(),
                    InsertedDate = c.DateTime(nullable: false),
                    LastUpdatedDate = c.DateTime(),
                })
            .PrimaryKey(t => t.EventId)
            .Index(t => t.EventId, unique: true);

    }

    public override void Down()
    {
        DropIndex("dbo.Event", new[] { "EventId" });
        DropTable("dbo.Event");
    }
}

模型

public class Event
{

    [Index(IsUnique = true)]
    public Int64 EventId { get; set; }

    public string Data { get; set; }

    public DateTime InsertedDate { get; set; }

    public DateTime? LastUpdatedDate { get; set; }
}

0 个答案:

没有答案