首次迁移EntityFramework代码中的EntityValidationError

我得到这个错误:

System.Data.Entity.Validation.DbEntityValidationException:一个或多个实体的验证失败。 有关更多详细信息,请参阅“EntityValidationErrors”属性。

在视觉工作室。 这里有几篇关于它的文章,但它们似乎都在应用程序流程中的某处运行“种子”方法。

在我的情况下,我试图在迁移的配置中对数据库进行种子处理。 如果这是不适当的,请让我知道。

现在有办法在运行Update-Database时以任何方式捕获异常或中断。 我如何查看错误消息的详细信息?

protected override void Seed(AppContext context)
        {


            User[] Users = new User[]
            {
                 new User()
                {
                    Id = new Guid().ToString(),
                    FirstMidName = "Arianne",
                    LastName = "Brower",
                    BirthDate = DateTime.Now,
                    UserType = UserType.Member,
                    Gender = Gender.Female,
                    ExerPoints = 500,
                    Contact = new Contact()
                    {
                        Address = "#2 HomeLand Rd, Central Town",
                        PhoneNumber = "1-868-555-0912",

                    }

                },
                new User()
                {
                    Id = new Guid().ToString(),
                    FirstMidName = "Melaino",
                    LastName = "Cruaino",
                    BirthDate = DateTime.Now,
                    UserType = UserType.Instructor,
                    Gender = Gender.Male,
                    ExerPoints = 1520,
                    Contact = new Contact()
                    {
                        Id = new Guid().ToString(),
                        Address = "#2 HomeLand Rd, Central Town",
                        PhoneNumber = "1-868-555-0912",

                    }
                },
                new User()
                {
                    Id = new Guid().ToString(),
                    FirstMidName = "Darion",
                    LastName = "Carpenter",
                    BirthDate = DateTime.Now,
                    UserType = UserType.Member,
                    Gender = Gender.Male,
                    ExerPoints = 2960,
                    Contact = new Contact()
                    {
                        Id = new Guid().ToString(),
                        Address = "#2 HomeLand Rd, Central Town",
                        PhoneNumber = "1-868-555-0912",

                    }
                },
                new User()
                {
                    Id = new Guid().ToString(),
                    FirstMidName = "Alexa",
                    LastName = "Bringer",
                    BirthDate = DateTime.Now,
                    UserType = UserType.Member,
                    Gender = Gender.Female,
                    ExerPoints = 3900,
                    Contact = new Contact()
                    {
                        Id = new Guid().ToString(),
                        Address = "#2 HomeLand Rd, Central Town",
                        PhoneNumber = "1-868-555-0912",

                    }
                },
                new User()
                {
                    Id = new Guid().ToString(),
                    FirstMidName = "Alexa",
                    LastName = "Bringer",
                    BirthDate = DateTime.Now,
                    UserType = UserType.Organizer,
                    Gender = Gender.Female,
                    ExerPoints = 12000,
                    Contact = new Contact()
                    {
                        Id = new Guid().ToString(),
                        Address = "#2 HomeLand Rd, Central Town",
                        PhoneNumber = "1-868-555-0912",

                    }
                }
            };


            context.Users.AddOrUpdate(Users);


            Club[] Clubs = new Club[]
            {
                new Club()
                {
                    Id = new Guid().ToString(),
                    Name = "Road Runners",
                    ContactInfo = new Contact() {
                        Id = new Guid().ToString(),
                        Address = "Lakanda Rd, POS",
                        PhoneNumber = "1-868-555-0011",
                        Website = "www.roadrunnerstt.tt"
                    },
                    PointsDistributed = 15950,
                    PointsEarned = 25500
                },
                new Club()
                {
                    Id = new Guid().ToString(),
                    Name = "Weightornators",
                    ContactInfo = new Contact() {
                        Id = new Guid().ToString(),
                        Address = "Lakanda Rd, POS",
                        PhoneNumber = "1-868-555-0011",
                        Website = "www.weightornators.tt"
                    },
                    PointsDistributed = 250000,
                    PointsEarned = 325000
                },
            };

            context.Clubs.AddOrUpdate(
                 Clubs
            );
        }
    }
链接地址: http://www.djcxy.com/p/90291.html

上一篇: EntityValidationError in EntityFramework Code first migration

下一篇: EntityFramework 6 Mysql .NET Connector 6.9.9 code first migrations