EntityValidationError in EntityFramework Code first migration
I am getting this error:
System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
In visual studio. There are several posts on here about it however all of them seem to be running a "seed" method somewhere in the application flow.
In my case I am trying to seed the database in the Configuration of the migrations. If that is ill advised please let me know.
There is now way to catch exceptions or break in any way when Update-Database
is run. How can I view the details of the error message?
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/90292.html