❔ 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
.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.'
Keyless Entity Types - EF Core
How to configure keyless entity types using Entity Framework Core
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.
add a key because it not having a key makes 0 sense, problem solved
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.