IDbSetExtensions.AddOrUpdate<TEntity> Method (IDbSet<TEntity>, TEntity[])

Entity Framework 5.0

Adds or updates entities by key when SaveChanges is called. Equivalent to an "upsert" operation from database terminology. This method can be useful when seeding data using Migrations.

Namespace:  System.Data.Entity.Migrations
Assembly:  EntityFramework (in EntityFramework.dll)

public static void AddOrUpdate<TEntity>(
	this IDbSet<TEntity> set,
	params TEntity[] entities
where TEntity : class

Type Parameters


The type of the Entity.


Type: System.Data.Entity.IDbSet<TEntity>

An IDbSet<TEntity> object that is used to perform create, read, update, and delete operations.

Type: TEntity[]

The entities to add or update.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IDbSet<TEntity>. When you use instance method syntax to call this method, omit the first parameter. For more information, see or

When the set parameter is a custom or fake IDbSet<TEntity> implementation, this method will attempt to locate and invoke a public, instance method with the same signature as this extension method.