none
Having problem with inserting the data into entity framework database RRS feed

  • Question

  • Hello,

    I Having problem with inserting the data into entity framework database, this is my database design.

    I am getting error when I try to call the where routeID is the Route in the Bus.

    return _ctx.Buses.Include("routeID").AsQueryable();

    'System.Data.Entity.ModelConfiguration.ModelValidationException' occurred in EntityFramework.dll but was not handled in user code' and return me null.

    I am inserting into the database using Projectdataseeder class

    var passPoint1 = new PassPoint()
                    {
                        busID = new Bus()
                        {
                            Id = 1,
                            time = 5.0,
                            srcLong = 35.909042,
                            srcLat = 31.973699,
                            routeID = new Route()
                            {
                                Id = 1,
                                destLong = 35.933719,
                                destLat = 31.992418
                            }
                        },
                        poiID = new PointsOfInterests()
                        {
                            Id = 1,
                            locName = "The Speciality Hospital",
                            locLong = 35.902391,
                            locLat = 31.979922
                        }
                    };

    and this is URL to the project on onedrive THIS IS THE PROJECT And for the reference I used THIS IS THE REFRENCE.

    plz guys can u help I believe the problem in the mappers or the seeding but I don't know how to fix it. or maybe in the loc.web all my life depend on this project its graduation :D.

    Regards,

    Ayesh

    Thursday, October 29, 2015 10:06 AM

Answers

  • I downloaded your project while I see there is not html page in the web project… So I changed the data class library to be a console application and made a test with it, and it occurred an exception when creating the database, this error occurring on my side showed your PassPoint entity did not have a primary key. I checked the entity class and it was that. So to fix it was just to add an int type property as:

    public int PassPointID { get; set; } 

    And set it to be the primary key in PassPointMapper class:

    this.HasKey(pp => pp.PassPointID); 

    It then could work fine. Please have a try and if this does not work for you, please feel free to let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, October 30, 2015 3:16 AM
    Moderator

All replies

  • Hi Ayesh,

    Like your title mentioned, your case more related to entity framework database, I will move your case to EF forum for better support.

    Have a nice day!

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, October 30, 2015 2:17 AM
  • I downloaded your project while I see there is not html page in the web project… So I changed the data class library to be a console application and made a test with it, and it occurred an exception when creating the database, this error occurring on my side showed your PassPoint entity did not have a primary key. I checked the entity class and it was that. So to fix it was just to add an int type property as:

    public int PassPointID { get; set; } 

    And set it to be the primary key in PassPointMapper class:

    this.HasKey(pp => pp.PassPointID); 

    It then could work fine. Please have a try and if this does not work for you, please feel free to let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, October 30, 2015 3:16 AM
    Moderator