0

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
            );
        }
    }
xerotolerant
  • 1,955
  • 4
  • 21
  • 39
  • Why not simple catch the exeption, [process it](http://stackoverflow.com/questions/15820505/dbentityvalidationexception-how-can-i-easily-tell-what-caused-the-error), log to `Debug.WriteLine` and rethrow? – Christian Gollhardt Jan 25 '17 at 03:07
  • I tried that. It seems to produce no output to the console when `Update-Database` is run in the package manager console. Breakpoints also do not appear to work – xerotolerant Jan 25 '17 at 03:09
  • Maybe you could try to log it to the eventconsole or a filestream – Christian Gollhardt Jan 25 '17 at 03:10
  • What are either of those things and where would I find them? – xerotolerant Jan 25 '17 at 03:10
  • [StreamWriter](https://msdn.microsoft.com/en-us/library/3zc0w663(v=vs.110).aspx) or [Eventlog](http://stackoverflow.com/questions/25725151/write-to-windows-application-event-log-without-registering-an-event-source) – Christian Gollhardt Jan 25 '17 at 03:12
  • The EventLog seemed to be ignored as well. I tried wrapping the AddOrUpdate methods in a `try catch` block and outputting the values to the event log using but there is nothing there to match what I put out. – xerotolerant Jan 25 '17 at 03:25
  • Maybe this could be relevant for you? http://stackoverflow.com/questions/17169020/debug-code-first-entity-framework-migration-codes – Christian Gollhardt Jan 25 '17 at 03:28

0 Answers0