How to fix the datetime2 out-of-range conversion error using DbContext and SetInitializer?

前端 未结 15 885
-上瘾入骨i
-上瘾入骨i 2020-12-07 19:39

I\'m using the DbContext and Code First APIs introduced with Entity Framework 4.1.

The data model uses basic data types such as string

15条回答
  •  隐瞒了意图╮
    2020-12-07 20:14

    initialize the Start property in the constructor

    Start = DateTime.Now;
    

    This worked for me when I was trying to add few new fields to the ASP .Net Identity Framework's Users table (AspNetUsers) using Code First. I updated the Class - ApplicationUser in IdentityModels.cs and I added a field lastLogin of type DateTime.

    public class ApplicationUser : IdentityUser
        {
            public ApplicationUser()
            {
                CreatedOn = DateTime.Now;
                LastPassUpdate = DateTime.Now;
                LastLogin = DateTime.Now;
            }
            public String FirstName { get; set; }
            public String MiddleName { get; set; }
            public String LastName { get; set; }
            public String EmailId { get; set; }
            public String ContactNo { get; set; }
            public String HintQuestion { get; set; }
            public String HintAnswer { get; set; }
            public Boolean IsUserActive { get; set; }
    
            //Auditing Fields
            public DateTime CreatedOn { get; set; }
            public DateTime LastPassUpdate { get; set; }
            public DateTime LastLogin { get; set; }
        }
    

提交回复
热议问题