I'm writing an application using EF6 Code First, and exposing my entities via OData endpoints. I have what is essentially a change tracking entity that keeps track of all previous values of another entity; something similar to the following:
public class QuizAnswerHistory
{
[Key]
public int StudentId { get; set; }
[Key]
public int QuestionId { get; set; }
[Key]
public DateTime ModifiedDate { get; set; }
public string AnswerValue { get; set; }
}
I also have a QuizAnswer
entity, which has exactly the same properties, except it's composite primary key doesn't include ModifiedDate
. It references only a Student
entity, and a Question
entity.
Now, because I want to be able to get the entire QuizAnswerHistory
entity for a specific Student/Question
, I don't want to have to specify the ModifiedDate
in my OData request.
However, because the ModifiedDate
is a primary key, when I send a GET request to /odata/QuizAnswerHistory(StudentId=1,QuestionId=2)
, I get the error, "The number of primary key values passed must match number of primary key values defined on the entity."
Is it possible to keep the ModifiedDate
as a primary key, but not require it in my requests?
There are 2 options to resolve the issue: