The property 'Id' on entity type 'EntityType' has a temporary value while attempting to change the entity's state
See original GitHub issue
Whilst making an insertion in to the db of an entity I’ve recently started receiving this and i can’t see why …
The property ‘Id’ on entity type ‘Page’ has a temporary value while attempting to change the entity’s state to ‘Unchanged’. Either set a permanent value explicitly or ensure that the database is configured to generate values for this property.
The entity definition begins with …
[Table("Pages", Schema = "CMS")]
public class Page
{
[Key]
public int Id { get; set; }
...
… the resulting EF Core migration generates this …
migrationBuilder.CreateTable(
name: "Pages",
schema: "CMS",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Which in turn looks like this when run on the DB server …

… I can’t see any reason why the primary key for that table isn’t entirely managed by EF / SQL here so when I do osmething like …
var newPage = context.Add(new Page { … });
… and leave the Id on it’s default I would expect the newPage variable to be populated with a DB generated primary key value.
What am I missing here?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:27 (10 by maintainers)
Top Related StackOverflow Question
That right there is the source of most of my frustrations with all .Net stack based solutions. It’s like there is no official guideline about what is compatible with what and if you find a scenario that sits in the gap between two frameworks the answer is usually cryptic or vague.
The net result is often that simply explaining the issue is non trivial and even if you agree that my issue is a genuine “problem in the technology” I still have the issue of trying to convince someone on one team or another that they should own the issue.
It would really help if teams on your end collaborated more to discuss feature sets and released guidelines and version “sets” of the various pieces that we are (as consumers) trying to bolt together. e.g OData + EF seems like a no brainer and yet rarely is.
Try updating the entities to something like this (although I admit I can’t see how this would affect the outcome) …
… or maybe the issue is that the primary keys are all guids? I have noticed some odd stuff with Guid keys, despite using the DatabaseGenerated attribute it doesn’t always set the system up to generate them on the db.
I wonder if it’s caused by the parent PK being computed and not given to the child entity set before the add. I’ll check through the history of my code to see if that could be related to my problem. Or maybe some mix of db generated guids and code generated guids i’m missing in my code.