1

I am unable to create the exact model from the official sql query as model to run the exact migration and create the table with exact properties.

    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

But it seems I cant create the exact table with code first.

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");
    }
}

The model

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; }
}
nightowl
  • 309
  • 1
  • 3
  • 13
  • you should describe the problem/error you are having – thepirat000 Feb 22 '19 at 17:00
  • Table is created. While Sql Provider is trying add new audit(this is seen as adding new id in the table it does not save the audit. I have fixed this by creating the table manually(but i am not sure it is the right way) but executing the query and now it works but i am using only audit.mvc. Still figuring out how to implement audit,EntittyFramework. – nightowl Feb 24 '19 at 11:38

0 Answers0