简体   繁体   中英

Entity framework and migration with datetime

I am using EF 4.3 and the migration script the come along. But I have an issue with a property that does not get his field created.

public class Test {
    [HiddenInput(DisplayValue = false)]
    public int Id { get; set; }

    [ScaffoldColumn(false)]
    public string Author { get; set; }

    [ScaffoldColumn(false)]
    public DateTime UpdateUtc { get; set; }

}

When I run the command Add-Migration here is the code that is generate:

    public override void Up()
    {
        CreateTable(
            "Test",
            c => new
                {
                    Id = c.Int(nullable: false, identity: true),
                    Author = c.String(),
                })
            .PrimaryKey(t => t.Id);

    }

My first thought was because of the ScaffoldColumn attribute but the Author field is correctly add. The only difference I see is that the type of the field UpdateUtc is not a primitive type.

What would cause this issue?

thanks

Try to add it by hand, using something like:

UpdateUtc = c.DateTime()

I think it should be it. Then update the database using Update command. When you generate the database, please look at the name of the column generated and see if it is something like [UpdateUtc]. If so, then the name UpdateUtc si reserved and cannot be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM