I am running into an issue where I am trying to list, edit, create, or delete data from a table in my database. When I do this error appears:
The number of primary key values passed must match number of primary
key values defined on the entity.
My issue is that there is a composite key but I cannot figure out how to declare that in my model. I did some searching and anything I found included adding [Key, Column(Order = 0)] however whenever I tried to add the column part, it would state that Column is not apart of the namespace. I have using System.ComponentModel.DataAnnotations; declared.
This is one of my models that need a composite key:
DateID, TimeID, ContactID all make up the primary key
ContactID, CountyNameID, CountyStateIS are all foreign keys
public System.DateTime DateID { get; set; }
public System.TimeSpan TimeID { get; set; }
public int ContactID { get; set; }
public string CountyNameID { get; set; }
public string CountyStateID { get; set; }
The Column attribute is in the System.ComponentModel.DataAnnotations.Schema namespace.
If you’re using Visual Studio, you can hold the CTRL + . down together and Visual Studio will suggest the namespace, if you have a reference to the assembly.
Hope it helps!