C
C#2y ago
CrosRoad95

❔ ef7 Inserting child entities without primary key

i have an entity "Blog", with child entities "posts", post does not have id, only 2 properties string content and int blogid ef don't let me track posts becuase they are lacking of key ( post has explicit HasNoKey() ). Am i forced to add key or i can do it in other way?
5 Replies
CrosRoad95
CrosRoad95OP2y ago
.AddRange/.Add methods are complaining because of: System.InvalidOperationException: 'Unable to track an instance of type 'Post' because it does not have a primary key. Only entity types with a primary key may be tracked.'
Angius
Angius2y ago
Why don't posts have an ID? Do they not have any sort of a primary key? How do you expect to handle relationship between the blog and its posts, if the posts have no primary key? Keyless entities are used for views, results of raw queries, and the like. Normally, you wouldn't use them.
Saber
Saber2y ago
add a key because it not having a key makes 0 sense, problem solved
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server