Export (0) Print
Expand All

IDbSetExtensions.AddOrUpdate<TEntity> Method (IDbSet<TEntity>, Expression<Func<TEntity, Object>>, 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,
	Expression<Func<TEntity, Object>> identifierExpression,
	params TEntity[] entities
)
where TEntity : class

Type Parameters

TEntity

The type of the Entity.

Parameters

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

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

identifierExpression
Type: System.Linq.Expressions.Expression<Func<TEntity, Object>>

An expression specifying the properties that should be used when determining whether an Add or Update operation should be performed.

entities
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 http://msdn.microsoft.com/en-us/library/bb384936(v=vs.103).aspx or http://msdn.microsoft.com/en-us/library/bb383977(v=vs.103).aspx.

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.

Show:
© 2014 Microsoft