IDbSetExtensions.AddOrUpdate 方法

定义

重载

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

调用 SaveChanges 时,按键添加或更新实体。 等效于数据库术语中的“upsert”操作。 使用迁移设定数据种子时,此方法非常有用。

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

调用 SaveChanges 时,通过自定义标识表达式添加或更新实体。 等效于数据库术语中的“upsert”操作。 使用迁移设定数据种子时,此方法非常有用。

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

调用 SaveChanges 时,按键添加或更新实体。 等效于数据库术语中的“upsert”操作。 使用迁移设定数据种子时,此方法非常有用。

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())

类型参数

TEntity

参数

entities
TEntity[]

要添加或更新的实体。

注解

当 参数是自定义或虚假的 IDbSet 实现时,此方法将尝试查找并调用具有与此扩展方法相同的签名的公共实例方法。

适用于

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

调用 SaveChanges 时,通过自定义标识表达式添加或更新实体。 等效于数据库术语中的“upsert”操作。 使用迁移设定数据种子时,此方法非常有用。

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())

类型参数

TEntity

参数

identifierExpression
Expression<Func<TEntity,Object>>

一个表达式,指定在确定是否应执行 Add 或 Update 操作时应使用的属性。

entities
TEntity[]

要添加或更新的实体。

注解

当 参数是自定义或虚假的 IDbSet 实现时,此方法将尝试查找并调用具有与此扩展方法相同的签名的公共实例方法。

适用于