This behavior was expected in 3.0?
Yes, it is one of the 3.0 Breaking Changes – Temporary key values are no longer set onto entity instances.
The proposed solutions there are:
- Not using store-generated keys.
- Setting navigation properties to form relationships instead of setting foreign key values.
- Obtain the actual temporary key values from the entity’s tracking information. For example,
context.Entry(blog).Property(e => e.Id).CurrentValu
e will return the temporary value even thoughblog.Id
itself hasn’t been set.
Option #1 doesn’t make sense (apparently the affected places already use store generated keys).
Option #2 is preferable if you have navigation properties.
Option #3 is closer to the previous behavior, but requires access to the db context.