DbSetMigrationsExtensions.AddOrUpdate<TEntity> Method (IDbSet<TEntity>, Expression<Func<TEntity, Object>>, TEntity[])
[This page is specific to the Entity Framework version 6. The latest version is available as the 'Entity Framework' NuGet package. For more information about Entity Framework, see msdn.com/data/ef.]
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.
Namespace: System.Data.Entity.Migrations
Assembly: EntityFramework (in EntityFramework.dll)
Syntax
'Declaration
<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")> _
<ExtensionAttribute> _
Public Shared Sub AddOrUpdate(Of TEntity As Class) ( _
set As IDbSet(Of TEntity), _
identifierExpression As Expression(Of Func(Of TEntity, Object)), _
ParamArray entities As TEntity() _
)
'Usage
Dim set As IDbSet(Of TEntity)
Dim identifierExpression As Expression(Of Func(Of TEntity, Object))
Dim entities As TEntity()
set.AddOrUpdate(identifierExpression, _
entities)
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public static void AddOrUpdate<TEntity>(
this IDbSet<TEntity> set,
Expression<Func<TEntity, Object>> identifierExpression,
params TEntity[] entities
)
where TEntity : class
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1006:DoNotNestGenericTypesInMemberSignatures")]
[ExtensionAttribute]
public:
generic<typename TEntity>
where TEntity : ref class
static void AddOrUpdate(
IDbSet<TEntity>^ set,
Expression<Func<TEntity, Object^>^>^ identifierExpression,
... array<TEntity>^ entities
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
static member AddOrUpdate :
set:IDbSet<'TEntity> *
identifierExpression:Expression<Func<'TEntity, Object>> *
entities:'TEntity[] -> unit when 'TEntity : not struct
JScript does not support generic types and methods.
Type Parameters
- TEntity
The type of entities to add or update.
Parameters
- set
Type: System.Data.Entity.IDbSet<TEntity>
The set to which the entities belong.
- 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 https://msdn.microsoft.com/en-us/library/bb384936(v=vs.113) or https://msdn.microsoft.com/en-us/library/bb383977(v=vs.113).
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.