What happened to AddOrUpdate in EF 7 / Core?

It's waiting to be implemented. See issues #629 & #4526.

Update: according to comments below (unverified) - this feature is finally slated for release in .NET Core 2.1!


The following MS Docs article, Disconnected entities, says that just using an Update will act as an AddOrUpdate from EF Core 2.0 onwards, as long as the primary key column in the database has an auto-generated (eg identity) value.

To quote from the article:

If it is known whether or not an insert or update is needed, then either Add or Update can be used appropriately.

However, if the entity uses auto-generated key values, then the Update method can be used for both cases.

The Update method normally marks the entity for update, not insert. However, if the entity has a auto-generated key, and no key value has been set, then the entity is instead automatically marked for insert.

This behavior was introduced in EF Core 2.0. For earlier releases it is always necessary to explicitly choose either Add or Update.

If the entity is not using auto-generated keys, then the application must decide whether the entity should be inserted or updated.

I've tried this out in a test project and can confirm that Update works for both adding and updating an entity in EF Core 2.2, with an auto-generated key.

The Disconnected entities article linked above also includes sample code for a homemade InsertOrUpdate method, for earlier versions of EF Core or if the entity doesn't have an auto-generated key. The sample code is specific to a particular entity class and would need modification to make it generalized.