Reputation: 7092
I'm trying to scaffold a new API controller using NetCore Entity Framework. However, I am getting this error: "cannot be added because it targets the keless entity type RobotResponses"
In the database, RobotResponses is a table with no primary key. But it has two columns named SessionId and HumanId that are both foreign keys, and have an Index like this: uq_RobotResponses_sessionId_humanId
Now, in my code, should I make both properties keys like this?
[Key]
public long SessionId { get; set; }
[Key]
public long HumanId { get; set; }
Thanks!
Upvotes: 0
Views: 117
Reputation: 1956
What you’re looking for is something called Composite Keys. You configure it in the fluent api like this: https://www.learnentityframeworkcore.com/configuration/fluent-api/haskey-method
Upvotes: 1