LINQ Query Exception error Invalid column name 'courseId1' EFCore

c# entity-framework entity-framework-core linq

Question

I am trying to run a LINQ Query to a database context:

  IList<meeting> meetings;

        var festivalRange = new
        {
            Start = festivalStartDate.Date,
            End = festivalStartDate.Date.AddDays(festivalLength - 1)
        };

        using(CamelotViewsStandardContext db = new CamelotViewsStandardContext() )
        {
            meetings = db.meetings.Include("races").Where(x => x.courseId == 10 && x.meetingDate >= festivalRange.Start && x.meetingDate <= festivalRange.End).OrderBy(x => x.meetingDate).ToList();
        }

I get the following error, no matter what type of query I try to do:

Exception thrown: 'System.Data.SqlClient.SqlException' in 
Microsoft.EntityFrameworkCore.dll
An exception of type 'System.Data.SqlClient.SqlException' occurred in 
Microsoft.EntityFrameworkCore.dll but was not handled in user code
Invalid column name 'courseId1'.

There is no 'courseId1' in my database table or mapped to the entity model.

Here is my 'meetings' model builder and model:

            //Meeting
        modelBuilder.Entity<meeting>(entity =>
        {
            entity.ToTable("meeting_vw");
            entity.HasMany(x => x.races).WithOne(c => c.meeting);
            entity.HasKey(x => x.courseId);
            entity.HasKey(x => x.meetingDate);
        });


 public class meeting : IMeetingKey
{
    public DateTime meetingDate { get; set; }

    /// <summary>
    ///The ID of the course of the meeting and is part of the primary key
    ///</summary>
    ///<value>Above 0</value>
    ///<returns>Integer</returns>
    ///<remarks>Part of the primary key (PK)</remarks>
    ///<permission>Standard</permission>
    public int courseId { get; set; }

    /// <summary>
    ///The full name of the course that of the meeting
    ///</summary>
    ///<value>Upper case</value>
    ///<returns>String</returns>
    ///<remarks>An example: HAYDOCK PARK</remarks>
    ///<permission>Standard</permission>
    public string courseName { get; set; }

    /// <summary>
    ///The type of surface that is raced on at the meeting
    ///</summary>
    ///<value>Title case</value>
    ///<returns>String</returns>
    ///<remarks>Values are All Weather, Turf or Both</remarks>
    ///<permission>Standard</permission>
    public string meetingSurfaceName { get; set; }

    /// <summary>
    ///The one character representation of the type of surface that is raced on at the meeting
    ///</summary>
    ///<value>One char</value>
    ///<returns>String(1)</returns>
    ///<remarks>Values are A - All Weather, T - Turf, B - Both</remarks>
    ///<permission>Standard</permission>
    public string meetingSurfaceChar { get; set; }

    /// <summary>
    ///The status of the meeting
    ///</summary>
    ///<value>"" If no status is available, title case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" - no status available, an example: Abandoned</remarks>
    ///<permission>Standard</permission>
    public string meetingStatus { get; set; }

    /// <summary>
    ///The type of racing
    ///</summary>
    ///<value>Title Case</value>
    ///<returns></returns>
    ///<remarks>Values are Flat, Jump, Both</remarks>
    ///<permission>Standard</permission>
    public string meetingRaceType { get; set; }

    /// <summary>
    ///The suffix of the meeting number as per the racing calendar
    ///</summary>
    ///<value>"" if no suffix is available, upper case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" - no suffix, an example: B</remarks>
    ///<permission>Standard</permission>
    public string meetingNumberSuffix { get; set; }

    /// <summary>
    ///The meeting number as per the racing calendar
    ///</summary>
    ///<value>0 if no number is available, positive integer if it is</value>
    ///<returns>Integer</returns>
    ///<remarks>0 - no meeting number, an example 255</remarks>
    ///<permission>Standard</permission>
    public int meetingNumber { get; set; }

    /// <summary>
    ///The time that any inspection is due to take place
    ///</summary>
    ///<value>1900-01-01 00:00:00.000 if no inspection is to take place, valid date time if it is</value>
    ///<returns>Date Time</returns>
    ///<remarks>1900-01-01 00:00:00.000 - no inspection, an example 2015-06-01 10:30:27.234</remarks>
    ///<permission>Standard</permission>
    public DateTime inspectionTime { get; set; }

    /// <summary>
    ///The official going report for the meeting
    ///</summary>
    ///<value>"" if no report is available, title case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" - no report, </remarks>
    ///<permission>Standard</permission>
    public string meetingGoing { get; set; }


    /// <summary>
    ///Internal Publish Flag
    ///</summary>
    ///<value>Internal Use Only</value>
    ///<returns>Integer</returns>
    ///<remarks>Internal Use Only</remarks>
    ///<permission>Standard</permission>
    public int publishFlag { get; set; }

    public course course { get; set; }
    public List<race> races { get; set; } = new List<race>();
}

I am starting to think this is an issue with the 'races' linking part of the models.

Here is the races modelbuilder and model:

            //Races
        modelBuilder.Entity<race>(entity =>
        {
            entity.ToTable("race_standard_vw");
            entity.HasKey(x => x.meetingDate);
            entity.HasKey(x => x.courseId);
            entity.HasKey(x => x.raceNumber);
        });

    public class race : IRaceKey
{

    /// <summary>
    ///The date of the race and part of the primary key
    ///</summary>
    ///<value>Not Null</value>
    ///<returns>Date</returns>
    ///<remarks>Date of the race in the format yyyy-mm-dd</remarks>
    ///<permission>Standard</permission>
    public DateTime meetingDate { get; set; }

    /// <summary>
    ///The ID of the course that the race took place at and is part of the primary key
    ///</summary>
    ///<value>Above 0</value>
    ///<returns>Integer</returns>
    ///<remarks>Part of the primary key (PK)</remarks>
    ///<permission>Standard</permission>
    public int courseId { get; set; }

    /// <summary>
    ///The number of the race and is part of the primary key
    ///</summary>
    ///<value>1 or higher</value>
    ///<returns>Integer</returns>
    ///<remarks>Part of the primary key (PK)</remarks>
    ///<permission>Standard</permission>
    public int raceNumber { get; set; }

    /// <summary>
    ///The full name of the course
    ///</summary>
    ///<value>Upper Case</value>
    ///<returns>String</returns>
    ///<remarks>An example: HAYDOCK PARK</remarks>
    ///<permission>Standard</permission>
    public string courseName { get; set; }

    /// <summary>
    ///The 3 character course abbreviation
    ///</summary>
    ///<value>Title Case</value>
    ///<returns>String(3)</returns>
    ///<remarks>An example: Hay</remarks>
    ///<permission>Standard</permission>
    public string courseAbbrev { get; set; }

    /// <summary>
    ///The time that the race was due to start where the race was being run
    ///</summary>
    ///<value>yyyy-mm-ddd hh:mm:ss:ms</value>
    ///<returns>Date Time</returns>
    ///<remarks>Defaults to 1990-01-01 00:00:00.000 if not available, an example: 2012-02-19 13:10:00.000</remarks>
    ///<permission>Standard</permission>
    public DateTime startTimeLocalScheduled { get; set; }

    /// <summary>
    ///The time that the race was due to start at GMT
    ///</summary>
    ///<value>yyyy-mm-ddd hh:mm:ss:ms</value>
    ///<returns>Date Time</returns>
    ///<remarks>Defaults to 1990-01-01 00:00:00.000 if not available, an example: 2012-02-19 13:10:00.000</remarks>
    ///<permission>Standard</permission>
    public DateTime startTimeGMTScheduled { get; set; }

    /// <summary>
    ///The time that the race actually started where the race was being run
    ///</summary>
    ///<value>yyyy-mm-ddd hh:mm:ss:ms</value>
    ///<returns>Date Time</returns>
    ///<remarks>Defaults to 1990-01-01 00:00:00.000 if not available, an example: 2012-02-19 13:10:00.000</remarks>
    ///<permission>Standard</permission>
    public DateTime actualTimeLocalScheduled { get; set; }


    /// <summary>
    ///The time that the race actually started at GMT
    ///</summary>
    ///<value>yyyy-mm-ddd hh:mm:ss:ms</value>
    ///<returns>Date Time</returns>
    ///<remarks>Defaults to 1990-01-01 00:00:00.000 if not available, an example: 2012-02-19 13:10:00.000</remarks>
    ///<permission>Standard</permission>
    public DateTime actualTimeGMTScheduled { get; set; }

    /// <summary>
    ///The type of surface that is being run on
    ///</summary>
    ///<value>Title Case</value>
    ///<returns>String</returns>
    ///<remarks>Values are All Weather or Turf </remarks>
    ///<permission>Standard</permission>
    public string raceSurfaceChar { get; set; }

    /// <summary>
    ///The one character representation of the type of surface of the race
    ///</summary>
    ///<value>Title Case</value>
    ///<returns>String</returns>
    ///<remarks>Values are A or T </remarks>
    ///<permission>Standard</permission>
    public string raceSurfaceName { get; set; }

    /// <summary>
    ///The type of racing
    ///</summary>
    ///<value>Title Case</value>
    ///<returns>String</returns>
    ///<remarks>Values are Flat, Hurdle, Chase, Bumper</remarks>
    ///<permission>Standard</permission>
    public string raceType { get; set; }

    /// <summary>
    ///The number of complete furlongs the race will be run over
    ///</summary>
    ///<value>Above 0</value>
    ///<returns>Integer</returns>
    ///<remarks>an example: 8</remarks>
    ///<permission>Standard</permission>
    public int distanceFurlongs { get; set; }

    /// <summary>
    ///The number of yards the race will be run over in addition to the furlongs
    ///</summary>
    ///<value>May be 0 if the race is at an exact furlong distance</value>
    ///<returns>Integer</returns>
    ///<remarks>an example: 212</remarks>
    ///<permission>Standard</permission>
    public int distanceYards { get; set; }

    /// <summary>
    ///The race distance in decimal furlongs
    ///</summary>
    ///<value>Above 0.0</value>
    ///<returns>Decimal</returns>
    ///<remarks>an example: 8.51</remarks>
    ///<permission>Standard</permission>
    public decimal distance { get; set; }

    /// <summary>
    ///The race distance as text format
    ///</summary>
    ///<value>Display text for the distance of the race</value>
    ///<returns>String</returns>
    ///<remarks>an example: 1M 4F 50y</remarks>
    ///<permission>Standard</permission>
    public string distanceText { get; set; }

    /// <summary>
    ///The full name of the race
    ///</summary>
    ///<value>Upper Case</value>
    ///<returns>String</returns>
    ///<remarks>An Example: BETFRED CHELTENHAM GOLD CUP (Grade 1)</remarks>
    ///<permission>Standard</permission>
    public string raceTitle { get; set; }

    /// <summary>
    ///The short name of the race
    ///</summary>
    ///<value>Title case</value>
    ///<returns>String</returns>
    ///<remarks>An Example: Cheltenham Gold Cup</remarks>
    ///<permission>Standard</permission>
    public string raceTitleShort { get; set; }

    /// <summary>
    ///The Timeform going of the race
    ///</summary>
    ///<value>"" if no report is available, char if it is</value>
    ///<returns>String</returns>
    ///<remarks>Gd/Frm, Good, Soft, Gd/Sft</remarks>
    ///<permission>Standard</permission>
    public string going { get; set; }

    /// <summary>
    ///The Timeform single character going abbreviation
    ///</summary>
    ///<value>"" if no report is available, char if it is</value>
    ///<returns>String(1)</returns>
    ///<remarks>m, g, s, d</remarks>
    ///<permission>Standard</permission>
    public string goingAbbrev { get; set; }

    /// <summary>
    ///The official going of the race
    ///</summary>
    ///<value>"" if no report is available, Title Case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" - no report, </remarks>
    ///<permission>Standard</permission>
    public string goingOfficial { get; set; }

    /// <summary>
    ///The maximum age eligibility of the race
    ///</summary>
    ///<value>Can be an integer or a char</value>
    ///<returns>String(1)</returns>
    ///<remarks>If integer then that is the explicit age max, + = no max age, O - limited to the min age</remarks>
    ///<permission>Standard</permission>
    public string eligibilityAgeMax { get; set; }

    /// <summary>
    ///The minimum age eligibility of the race
    ///</summary>
    ///<value>Above 0</value>
    ///<returns>Integer</returns>
    ///<remarks>An example: 4</remarks>
    ///<permission>Standard</permission>
    public int? eligibilityAgeMin { get; set; }

    /// <summary>
    ///The number of runners either currently entered or that ran in the race
    ///</summary>
    ///<value>If 0, the value hasnt yet been calculated, above 0 if it has</value>
    ///<returns>Integer</returns>
    ///<remarks>0 - runners not yet known, an example: 5</remarks>
    ///<permission>Standard</permission>
    public int numberOfRunners { get; set; }

    /// <summary>
    ///The number of horses that will qualify as being placed under standard bookmaking terms
    ///</summary>
    ///<value>Above 0</value>
    ///<returns>Integer</returns>
    ///<remarks>An example: 3</remarks>
    ///<permission>Standard</permission>
    public int numberOfPlaces { get; set; }

    /// <summary>
    ///Details of a sex limit on the race
    ///</summary>
    ///<value>"" if no limit is involved</value>
    ///<returns>String(2)</returns>
    ///<remarks>"" means there is no sex limit, F - fillies, M - mares, C - colts, G - Geldered</remarks>
    ///<permission>Standard</permission>
    public string eligibilitySexLimit { get; set; }

    /// <summary>
    ///The current status of the race
    ///</summary>
    ///<value>"" - no status available, title case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" - no status available, an example: "Weighed In"</remarks>
    ///<permission>Standard</permission>
    public string resultsStatus { get; set; }

    /// <summary>
    ///Character value for the type of race
    ///</summary>
    ///<value>Upper Case</value>
    ///<returns>String(1)</returns>
    ///<remarks>N - Bumper, F - Flat, H - Hurdle, C - Chase</remarks>
    ///<permission>Standard</permission>
    public string raceTypeChar { get; set; }

    /// <summary>
    ///Representation of the flavour of race (handicap, group etc)
    ///</summary>
    ///<value>"" If not available, upper case if it is</value>
    ///<returns>String(2)</returns>
    ///<remarks>"" - not available, an example: H</remarks>
    ///<permission>Standard</permission>
    public string raceCode { get; set; }

    /// <summary>
    ///Total prize fund of the race
    ///</summary>
    ///<value>0.0 if not available, above 0.0 if it is </value>''
    ///<returns>Decimal</returns>
    ///<remarks>0.0 - not available, an example 9000.00</remarks>
    ///<permission>Standard</permission>
    public decimal prizeFund { get; set; }

    /// <summary>
    ///Prize fund for the winner of the race
    ///</summary>
    ///<value>0.0 if not available, above 0.0 if it is </value>
    ///<returns>Decimal</returns>
    ///<remarks>0.0 - not available, an example 9000.00</remarks>
    ///<permission>Standard</permission>
    public decimal prizeFundWinner { get; set; }

    /// <summary>
    ///The Timeform Rating of Winner of the race 5 runnings ago
    ///</summary>
    ///<value>0 if not available, above 0 if it is</value>
    ///<returns>Integer</returns>
    ///<remarks>0 - not available, an example: 134</remarks>
    ///<permission>Premium</permission>
    public int trw1 { get; set; }

    /// <summary>
    ///The Timeform Rating of Winner of the race 4 runnings ago
    ///</summary>
    ///<value>0 if not available, above 0 if it is</value>
    ///<returns>Integer</returns>
    ///<remarks>0 - not available, an example: 134</remarks>
    ///<permission>Premium</permission>
    public int trw2 { get; set; }

    /// <summary>
    ///The Timeform Rating of Winner of the race 3 runnings ago
    ///</summary>
    ///<value>0 if not available, above 0 if it is</value>
    ///<returns>Integer</returns>
    ///<remarks>0 - not available, an example: 134</remarks>
    ///<permission>Premium</permission>
    public int trw3 { get; set; }

    /// <summary>
    ///The Timeform Rating of Winner of the race 2 runnings ago
    ///</summary>
    ///<value>0 if not available, above 0 if it is</value>
    ///<returns>Integer</returns>
    ///<remarks>0 - not available, an example: 134</remarks>
    ///<permission>Premium</permission>
    public int trw4 { get; set; }

    /// <summary>
    ///The Timeform Rating of Winner of the race last time
    ///</summary>
    ///<value>0 if not available, above 0 if it is</value>
    ///<returns>Integer</returns>
    ///<remarks>0 - not available, an example: 134</remarks>
    ///<permission>Premium</permission>
    public int trw5 { get; set; }

    /// <summary>
    ///The Timeform Weight For Age
    ///</summary>
    ///<value>"" - not available</value>
    ///<returns>String</returns>
    ///<remarks>Example: TWFA 3 9-4 TWFA 4 9-13 </remarks>
    ///<permission>Premium</permission>
    public string tfwfa { get; set; }

    /// <summary>
    ///The premium post-race review of the race
    ///</summary>
    ///<value>"" if the comment hasn't been written, Title Case if it has</value>
    ///<returns>String</returns>
    ///<remarks>"" - no comment written, an example: "Winner impressive, others disapointed"</remarks>
    ///<permission>Premium</permission>
    public string perspectiveComment { get; set; }

    /// <summary>
    ///The Timeform Analyst pre-race predictions for the race
    ///</summary>
    ///<value>"" if not available, Title Case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" - not available, an example: HURRICANE FLY looks certain to take this race</remarks>
    ///<permission>Standard</permission>
    public string analystVerdict { get; set; }

    /// <summary>
    ///The comment for flat racing which is based on analysis of previous races at this course over the same distance
    ///</summary>
    ///<value>"" if not available, Title Case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" - not available, an example: Strongly favours low</remarks>
    ///<permission>Standard</permission>
    public string drawComment { get; set; }

    /// <summary>
    ///Information about in play records at the course
    ///</summary>
    ///<value>"" if not available, title case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" - not available, an example: Dundalk ranked 18 of 21 flat Irish courses for horses beaten at 1.01</remarks>
    ///<permission>Standard</permission>
    public string ipHintsGeneral { get; set; }

    /// <summary>
    ///Information about horses in the race based on their past trading and run style information
    ///</summary>
    ///<value>"" if not available, title case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" - not available, an example: Buywise traded at 1.50 on its last start when losing but travelling strongly in rear</remarks>
    ///<permission>Standard</permission>
    public string ipHintsPriceRunStyle { get; set; }


    /// <summary>
    ///Information about horses in the race based on their past trading information
    ///</summary>
    ///<value>"" if not available, title case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" - not available, an example: Milarrow traded at more than 5 times BSP twice when winning during its last 5 starts., Celtus has traded at 50% or less of BSP 4 times on its last 5 starts. </remarks>
    ///<permission>Standard</permission>
    public string iPriceHistory { get; set; }

    /// <summary>
    ///A prediction on the likely pace of the race
    ///</summary>
    ///<value>"" if not available, title case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" - not available, an example: Strongly contested </remarks>
    ///<permission>Standard</permission>
    public string ipHintsOverallPace { get; set; }

    /// <summary>
    ///A prediction on the likely shape of the race
    ///</summary>
    ///<value>"" if not available, title case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" - not available, an example: Kruzhlinin is unlikely to get things its own way close up and could therefore prove vulnerable in the finish: With no shortage of likely pace-forcers, Parsnip Pete may have a running style that suits. </remarks>
    ///<permission>Standard</permission>
    public string ipHintsSpecificPace { get; set; }

    /// <summary>
    ///An integer value of the race state
    ///</summary>
    ///<value>0 - unknown, above 0 is a valid state</value>
    ///<returns>Integer</returns>
    ///<remarks>0 - unknown, an example 22 - weighed in</remarks>
    ///<permission>Standard</permission>
    public int raceStateId { get; set; }

    /// <summary>
    ///For handicaps the lower handicap mark for a horse to qualify to run
    ///</summary>
    ///<value>0 if not applicable, above 0 for a valid mark</value>
    ///<returns>Integer</returns>
    ///<remarks>0 - limit not applicable, an example 130</remarks>
    ///<permission>Standard</permission>
    public int ratingLimitLower { get; set; }

    /// <summary>
    ///For handicaps the upper handicap mark for a horse to qualify to run
    ///</summary>
    ///<value>0 if not applicable, above 0 for a valid mark</value>
    ///<returns>Integer</returns>
    ///<remarks>0 - limit not applicable, an example 130</remarks>
    ///<permission>Standard</permission>
    public int ratingLimitUpper { get; set; }

    /// <summary>
    ///The class of race
    ///</summary>
    ///<value>"" if not available, title case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" if not available, an example 2</remarks>
    ///<permission>Standard</permission>
    public string raceClass { get; set; }

    /// <summary>
    ///The highest priority stat for the race
    ///</summary>
    ///<value>"" if not available, title case if it is with standard formatting values - # separate, * bold</value>
    ///<returns>String</returns>
    ///<remarks>"" - not available, an example: #34%#James Doyle's strike rate on favourites since 01/01/2009 (rides *TIME CHECK*)</remarks>
    ///<permission>Standard</permission>
    public string smartStat1 { get; set; }

    /// <summary>
    ///The second highest priority stat for the race
    ///</summary>
    ///<value>"" if not available, title case if it is with standard formatting values - # separate, * bold</value>
    ///<returns>String</returns>
    ///<remarks>"" - not available, an example: #34%#James Doyle's strike rate on favourites since 01/01/2009 (rides *TIME CHECK*)</remarks>
    ///<permission>Standard</permission>
    public string smartStat2 { get; set; }

    /// <summary>
    ///The third highest priority stat for the race
    ///</summary>
    ///<value>"" if not available, title case if it is with standard formatting values - # separate, * bold</value>
    ///<returns>String</returns>
    ///<remarks>"" - not available, an example: #34%#James Doyle's strike rate on favourites since 01/01/2009 (rides *TIME CHECK*)</remarks>
    ///<permission>Standard</permission>
    public string smartStat3 { get; set; }

    /// <summary>
    ///The Betfair market ID of this race if mapped
    ///</summary>
    ///<value>"" if not mapped to a Betfair market, title case if it is</value>
    ///<returns>String</returns>
    ///<remarks>"" - no market mapped, an example: 12321 </remarks>
    ///<permission>Standard</permission>
    public string bfMarketId { get; set; }

    /// <summary>
    ///The finishing time of the race in seconds
    ///</summary>
    ///<value>0 if the time in unavailable</value>
    ///<returns>Decimal</returns>
    ///<remarks>0 - if no time available, an example: 130.52</remarks>
    ///<permission>Standard</permission>
    public decimal finishingTime { get; set; }

    /// <summary>
    ///The time it took the leader at the point the sectional was taken to complete the race
    ///</summary>
    ///<value>0 if the time in unavailable</value>
    ///<returns>Decimal</returns>
    ///<remarks>0 - if unavailable, measured in seconds to two decimal places</remarks>
    ///<permission>Premium</permission>
    public decimal leaderSectional { get; set; }

    public decimal winnerSectional { get; set; }

    public decimal distanceSectional { get; set; }

    public decimal sectionalFinishingTime { get; set; }

    // Additional fields MDB 2016-01-08
    public int courseExtraId { get; set; }
    public string distanceType { get; set; }
    public string tv { get; set; }
    public int perspectiveNumber { get; set; }

    public int hotRace { get; set; }

    public string raceId { get; set; }

    public int numberOfFencesJumped { get; set; }

    /// <summary>
    ///Internal Publish Flag
    ///</summary>
    ///<value>Internal Use Only</value>
    ///<returns>Integer</returns>
    ///<remarks>Internal Use Only</remarks>
    ///<permission>Standard</permission>
    [JsonIgnore]
    public int publishFlag { get; set; }


    public string paceMapsIdealPosition { get; set; }

    public string resultNotes { get; set; }


    public virtual meeting meeting { get; set; }
    public virtual List<entry> entries { get; set; } = new List<entry>();
    public virtual List<performance> performances { get; set; } = new List<performance>();
}

Any help will be appreciated. Thanks.

1
2
8/29/2019 11:45:53 AM

Accepted Answer

The problem is the composite PK mappings.

For Meetings:

entity.HasKey(x => x.courseId);
entity.HasKey(x => x.meetingDate);

and also for Races:

entity.HasKey(x => x.meetingDate);
entity.HasKey(x => x.courseId);
entity.HasKey(x => x.raceNumber);

There could be similar issue with other entities not shown here.

Looks like you expect that HasKey is additive. But in fact it is overriding, so every HasKey overrides the previous setting and fully redefines the PK to be the one specified for the call.

As shown in Keys (primary) documentation, the composite keys can only be defined fluently using anonymous type syntax new { x.Prop1, x.Prop2, … }. The same applies for any multiple property fluent mapping like alternate key, foreign key, index etc.

The correct PK configuration of the sample entities is respectively

entity.HasKey(x => new { x.courseId, x.meetingDate });

and

entity.HasKey(x => new { x.meetingDate, x.courseId, x.raceNumber });
2
8/29/2019 11:36:53 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow