score:2
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 });
Source: stackoverflow.com
Related Articles
- LINQ Query Exception error Invalid column name 'courseId1' EFCore
- Linq query giving Invalid column name "xyz" error
- LINQ Error Invalid Column Name on Group by sum
- Linq query leading to invalid column name SqlException
- How to write LINQ query with column name as parameter still in a type safe way
- 'Invalid column name [ColumnName]' on a nested linq query
- add where clauses to linq query with generic column name
- LINQ to SQL: Invalid column name 'DepartureGate', even though the column exists
- MVC Linq Query with dynamic column name in WHERE clause
- Getting 'Data source is an invalid type' when binding Linq query to Gridview
- Dynamically Set Column Name In LINQ Query
- Invalid column name. The name was never implemented in the code
- Assign a column value if it throws an exception in Linq query
- CRM 2011 - Compare years in LINQ Query - Gives an error : Invalid 'where' condition. An entity member is invoking an invalid property or method
- (Entity Framework) context.Database.SqlQuery return invalid object name for table but LINQ query works
- Datatable LINQ query throws exception for datetime column
- Exception in linq query for use "Type" for property name
- LINQ Union causing error if a column in the query is DateTime
- How do I create a linq query where the select column name is a variable
- LINQ Error Invalid Column when retrieving additional column value
- .Net EF I can't update the data in my db. Getting an Invalid column name exception
- Invalid column sqlException in Linq query after update to Core 2.0
- "Range variable name can be inferred only from a simple or qualified name with no arguments" error in linq query
- Error occurs when retrieving column values from a DataTable LINQ query
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Linq to Xml : Exception -The ' ' character, hexadecimal value 0x20, cannot be included in a name
- Linq error generic parameter or the query must use a nullable type
- Why does LINQ query throw an exception when I attempt to get a count of a type
- Linq To SQL: Sort Query by Arbitrary Property(Column) Name
- Error creating a Linq query
- In List<string>, how to use the Contains() method and check if value is empty
- Check all properties in List
- How to take elements from the same collection based on other atrributes
- Optimizing orderby sum in LINQ and Entity Framework
- Am I doing something wrong from a connection pooling point of view?
- Linq to Entity Join table with multiple OR conditions
- VB.Net LINQ link two datatables and show all columns
- Group Products by Brand then by Category - linq
- LINQ to Entities - sort by array
- "System.ArgumentOutOfRangeException" why is it showing? And why does the list<>number stop printing?
- L2S :Convert Sql query to Linq
- How to remove a List string element if it contains a string element from another List?
- Comparing sql with c# list in query?
- In clause in linq expression
- Finding distinct Points in a list (using 2 predicates)
- Linq where clause using filter object
- convert nested for each to linq
- C# Create a list of objects from an 2 IEnumerable instances containing only those objects with a value found in the second list
- Linq : filter duplicated line without taking account a column
- Can I get values from my database using this method but without generating the additional text?