Share via


DbSetMigrationsExtensions.AddOrUpdate Method

Definition

Overloads

AddOrUpdate<TEntity>(IDbSet<TEntity>, TEntity[])

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

AddOrUpdate<TEntity>(IDbSet<TEntity>, Expression<Func<TEntity,Object>>, TEntity[])

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

AddOrUpdate<TEntity>(IDbSet<TEntity>, TEntity[])

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

public static void AddOrUpdate<TEntity> (this System.Data.Entity.IDbSet<TEntity> set, params TEntity[] entities) where TEntity : class;
static member AddOrUpdate : System.Data.Entity.IDbSet<'Entity (requires 'Entity : null)> * 'Entity[] -> unit (requires 'Entity : null)
<Extension()>
Public Sub AddOrUpdate(Of TEntity As Class) (set As IDbSet(Of TEntity), ParamArray entities As TEntity())

Type Parameters

TEntity

The type of entities to add or update.

Parameters

set
IDbSet<TEntity>

The set to which the entities belong.

entities
TEntity[]

The entities to add or update.

Remarks

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

Applies to

AddOrUpdate<TEntity>(IDbSet<TEntity>, Expression<Func<TEntity,Object>>, TEntity[])

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

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static void AddOrUpdate<TEntity> (this System.Data.Entity.IDbSet<TEntity> set, System.Linq.Expressions.Expression<Func<TEntity,object>> identifierExpression, params TEntity[] entities) where TEntity : class;
static member AddOrUpdate : System.Data.Entity.IDbSet<'Entity (requires 'Entity : null)> * System.Linq.Expressions.Expression<Func<'Entity, obj>> * 'Entity[] -> unit (requires 'Entity : null)
<Extension()>
Public Sub AddOrUpdate(Of TEntity As Class) (set As IDbSet(Of TEntity), identifierExpression As Expression(Of Func(Of TEntity, Object)), ParamArray entities As TEntity())

Type Parameters

TEntity

The type of entities to add or update.

Parameters

set
IDbSet<TEntity>

The set to which the entities belong.

identifierExpression
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
TEntity[]

The entities to add or update.

Attributes

Remarks

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

Applies to