Search Results for

    Show / Hide Table of Contents

    Interface IUpdate<T1>

    Namespace: FreeSql
    Assembly: FreeSql.dll
    Syntax
    public interface IUpdate<T1>
    Type Parameters
    Name Description
    T1

    Methods

    | Improve this Doc View Source

    AsTable(Func<String, String>)

    设置表名规则,可用于分库/分表,参数1:默认表名;返回值:新表名;

    Declaration
    IUpdate<T1> AsTable(Func<string, string> tableRule)
    Parameters
    Type Name Description
    System.Func<System.String, System.String> tableRule
    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    AsTable(String)

    设置表名

    Declaration
    IUpdate<T1> AsTable(string tableName)
    Parameters
    Type Name Description
    System.String tableName
    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    AsType(Type)

    动态Type,在使用 Update<object> 后使用本方法,指定实体类型

    Declaration
    IUpdate<T1> AsType(Type entityType)
    Parameters
    Type Name Description
    System.Type entityType
    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    BatchOptions(Int32, Int32, Boolean)

    批量执行选项设置,一般不需要使用该方法

    各数据库 rows, parameters 限制不一样,默认设置:

    MySql 500 3000

    PostgreSQL 500 3000

    SqlServer 500 2100

    Oracle 200 999

    Sqlite 200 999

    若没有事务传入,内部(默认)会自动开启新事务,保证拆包执行的完整性。

    Declaration
    IUpdate<T1> BatchOptions(int rowsLimit, int parameterLimit, bool autoTransaction = true)
    Parameters
    Type Name Description
    System.Int32 rowsLimit

    指定根据 rows 上限数量拆分执行

    System.Int32 parameterLimit

    指定根据 parameters 上限数量拆分执行

    System.Boolean autoTransaction

    是否自动开启事务

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    BatchProgress(Action<BatchProgressStatus<T1>>)

    批量执行时,分批次执行的进度状态

    Declaration
    IUpdate<T1> BatchProgress(Action<BatchProgressStatus<T1>> callback)
    Parameters
    Type Name Description
    System.Action<BatchProgressStatus<T1>> callback

    批量执行时的回调委托

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    CommandTimeout(Int32)

    命令超时设置(秒)

    Declaration
    IUpdate<T1> CommandTimeout(int timeout)
    Parameters
    Type Name Description
    System.Int32 timeout
    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    DisableGlobalFilter(String[])

    禁用全局过滤功能,不传参数时将禁用所有

    Declaration
    IUpdate<T1> DisableGlobalFilter(params string[] name)
    Parameters
    Type Name Description
    System.String[] name

    零个或多个过滤器名字

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    ExecuteAffrows()

    执行SQL语句,返回影响的行数

    Declaration
    int ExecuteAffrows()
    Returns
    Type Description
    System.Int32
    | Improve this Doc View Source

    ExecuteAffrowsAsync(CancellationToken)

    Declaration
    Task<int> ExecuteAffrowsAsync(CancellationToken cancellationToken = default(CancellationToken))
    Parameters
    Type Name Description
    System.Threading.CancellationToken cancellationToken
    Returns
    Type Description
    System.Threading.Tasks.Task<System.Int32>
    | Improve this Doc View Source

    ExecuteUpdated()

    执行SQL语句,返回更新后的记录

    注意:此方法只有 Postgresql/SqlServer 有效果

    Declaration
    List<T1> ExecuteUpdated()
    Returns
    Type Description
    System.Collections.Generic.List<T1>
    | Improve this Doc View Source

    ExecuteUpdatedAsync(CancellationToken)

    Declaration
    Task<List<T1>> ExecuteUpdatedAsync(CancellationToken cancellationToken = default(CancellationToken))
    Parameters
    Type Name Description
    System.Threading.CancellationToken cancellationToken
    Returns
    Type Description
    System.Threading.Tasks.Task<System.Collections.Generic.List<T1>>
    | Improve this Doc View Source

    IgnoreColumns(Expression<Func<T1, Object>>)

    忽略的列,IgnoreColumns(a => a.Name) | IgnoreColumns(a => new{a.Name,a.Time}) | IgnoreColumns(a => new[]{"name","time"})

    注意:不能与 UpdateColumns 不能同时使用

    Declaration
    IUpdate<T1> IgnoreColumns(Expression<Func<T1, object>> columns)
    Parameters
    Type Name Description
    System.Linq.Expressions.Expression<System.Func<T1, System.Object>> columns

    lambda选择列

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    IgnoreColumns(String[])

    忽略的列

    注意:不能与 UpdateColumns 不能同时使用

    Declaration
    IUpdate<T1> IgnoreColumns(string[] columns)
    Parameters
    Type Name Description
    System.String[] columns

    属性名,或者字段名

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    Join<T2>(ISelect<T2>, Expression<Func<T1, T2, Boolean>>)

    联表更新(危险操作),支持更复杂的联表更新

    fsql.Update<T1>()

    .Join(fsql.Select<T1>(), (a, b) => a.id == b.id)

    .Set((a, b) => a.name == b.name)

    .Set((a, b) => a.time == b.time2)

    .ExecuteAffrows();

    Declaration
    IUpdateJoin<T1, T2> Join<T2>(ISelect<T2> query, Expression<Func<T1, T2, bool>> on)
        where T2 : class
    Parameters
    Type Name Description
    ISelect<T2> query
    System.Linq.Expressions.Expression<System.Func<T1, T2, System.Boolean>> on
    Returns
    Type Description
    IUpdateJoin<T1, T2>
    Type Parameters
    Name Description
    T2
    | Improve this Doc View Source

    Join<T2>(Expression<Func<T1, T2, Boolean>>)

    联表更新(危险操作)

    fsql.Update<T1>()

    .Join<T2>((a, b) => a.id == b.id)

    .Set((a, b) => a.name == b.name)

    .Set((a, b) => a.time == b.time2)

    .ExecuteAffrows();

    Declaration
    IUpdateJoin<T1, T2> Join<T2>(Expression<Func<T1, T2, bool>> on)
        where T2 : class
    Parameters
    Type Name Description
    System.Linq.Expressions.Expression<System.Func<T1, T2, System.Boolean>> on
    Returns
    Type Description
    IUpdateJoin<T1, T2>
    Type Parameters
    Name Description
    T2
    | Improve this Doc View Source

    NoneParameter(Boolean)

    不使用参数化,可通过 IFreeSql.CodeFirst.IsNotCommandParameter 全局性设置

    Declaration
    IUpdate<T1> NoneParameter(bool isNotCommandParameter = true)
    Parameters
    Type Name Description
    System.Boolean isNotCommandParameter

    是否不使用参数化

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    Set<TMember>(Expression<Func<T1, TMember>>)

    设置列的新值为基础上增加,格式:Set(a => a.Clicks + 1) 相当于 clicks=clicks+1

    指定更新,格式:Set(a => new T { Clicks = a.Clicks + 1, Time = DateTime.Now }) 相当于 set clicks=clicks+1,time='2019-06-19....'

    Declaration
    IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> exp)
    Parameters
    Type Name Description
    System.Linq.Expressions.Expression<System.Func<T1, TMember>> exp
    Returns
    Type Description
    IUpdate<T1>
    Type Parameters
    Name Description
    TMember
    | Improve this Doc View Source

    Set<TMember>(Expression<Func<T1, TMember>>, TMember)

    设置列的新值,Set(a => a.Name, "newvalue")

    Declaration
    IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> column, TMember value)
    Parameters
    Type Name Description
    System.Linq.Expressions.Expression<System.Func<T1, TMember>> column

    lambda选择列

    TMember value

    新值

    Returns
    Type Description
    IUpdate<T1>
    Type Parameters
    Name Description
    TMember
    | Improve this Doc View Source

    SetDto(Object)

    设置更新的列

    SetDto(new { title = "xxx", clicks = 2 })

    SetDto(new Dictionary<string, object> { ["title"] = "xxx", ["clicks"] = 2 })

    注意:标记 [Column(CanUpdate = false)] 的属性不会被更新

    Declaration
    IUpdate<T1> SetDto(object dto)
    Parameters
    Type Name Description
    System.Object dto

    dto 或 Dictionary<string, object>

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    SetIf<TMember>(Boolean, Expression<Func<T1, TMember>>)

    设置列的新值为基础上增加,格式:Set(a => a.Clicks + 1) 相当于 clicks=clicks+1

    指定更新,格式:Set(a => new T { Clicks = a.Clicks + 1, Time = DateTime.Now }) 相当于 set clicks=clicks+1,time='2019-06-19....'

    Declaration
    IUpdate<T1> SetIf<TMember>(bool condition, Expression<Func<T1, TMember>> exp)
    Parameters
    Type Name Description
    System.Boolean condition

    true 时生效

    System.Linq.Expressions.Expression<System.Func<T1, TMember>> exp
    Returns
    Type Description
    IUpdate<T1>
    Type Parameters
    Name Description
    TMember
    | Improve this Doc View Source

    SetIf<TMember>(Boolean, Expression<Func<T1, TMember>>, TMember)

    设置列的新值,Set(a => a.Name, "newvalue")

    Declaration
    IUpdate<T1> SetIf<TMember>(bool condition, Expression<Func<T1, TMember>> column, TMember value)
    Parameters
    Type Name Description
    System.Boolean condition

    true 时生效

    System.Linq.Expressions.Expression<System.Func<T1, TMember>> column

    lambda选择列

    TMember value

    新值

    Returns
    Type Description
    IUpdate<T1>
    Type Parameters
    Name Description
    TMember
    | Improve this Doc View Source

    SetRaw(String, Object)

    设置值,自定义SQL语法,SetRaw("title = @title&quot;, new { title = "newtitle" })

    提示:parms 参数还可以传 Dictionary<string, object>

    Declaration
    IUpdate<T1> SetRaw(string sql, object parms = null)
    Parameters
    Type Name Description
    System.String sql

    sql语法

    System.Object parms

    参数

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    SetSource(T1)

    更新数据,设置更新的实体

    注意:实体必须定义主键,并且最终会自动附加条件 where id = source.Id

    Declaration
    IUpdate<T1> SetSource(T1 source)
    Parameters
    Type Name Description
    T1 source

    实体

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    SetSource(IEnumerable<T1>, Expression<Func<T1, Object>>, Boolean)

    更新数据,设置更新的实体集合

    注意:实体必须定义主键,并且最终会自动附加条件 where id in (source.Id)

    Declaration
    IUpdate<T1> SetSource(IEnumerable<T1> source, Expression<Func<T1, object>> tempPrimarys = null, bool ignoreVersion = false)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<T1> source

    实体集合

    System.Linq.Expressions.Expression<System.Func<T1, System.Object>> tempPrimarys

    根据临时主键更新,a => a.Name | a => new{a.Name,a.Time} | a => new[]{"name","time"}

    System.Boolean ignoreVersion

    忽略 IsVersion 乐观锁版本号

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    SetSourceIgnore(T1, Func<Object, Boolean>)

    更新数据,设置更新的实体,同时设置忽略的列

    忽略 null 属性:fsql.Update<T>().SetSourceAndIgnore(item, colval => colval == null)

    注意:参数 ignore 与 IUpdate.IgnoreColumns/UpdateColumns 不能同时使用

    Declaration
    IUpdate<T1> SetSourceIgnore(T1 source, Func<object, bool> ignore)
    Parameters
    Type Name Description
    T1 source

    实体

    System.Func<System.Object, System.Boolean> ignore

    属性值忽略判断, true忽略

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    ToSql()

    返回即将执行的SQL语句

    Declaration
    string ToSql()
    Returns
    Type Description
    System.String
    | Improve this Doc View Source

    UpdateColumns(Expression<Func<T1, Object>>)

    指定的列,UpdateColumns(a => a.Name) | UpdateColumns(a => new{a.Name,a.Time}) | UpdateColumns(a => new[]{"name","time"})

    注意:不能与 IgnoreColumns 不能同时使用

    Declaration
    IUpdate<T1> UpdateColumns(Expression<Func<T1, object>> columns)
    Parameters
    Type Name Description
    System.Linq.Expressions.Expression<System.Func<T1, System.Object>> columns

    lambda选择列

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    UpdateColumns(String[])

    指定的列

    注意:不能与 IgnoreColumns 同时使用

    Declaration
    IUpdate<T1> UpdateColumns(string[] columns)
    Parameters
    Type Name Description
    System.String[] columns

    属性名,或者字段名

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    Where(T1)

    传入实体,将主键作为条件

    Declaration
    IUpdate<T1> Where(T1 item)
    Parameters
    Type Name Description
    T1 item

    实体

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    Where(IEnumerable<T1>)

    传入实体集合,将主键作为条件

    Declaration
    IUpdate<T1> Where(IEnumerable<T1> items)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<T1> items

    实体集合

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    Where(Expression<Func<T1, Boolean>>)

    lambda表达式条件,仅支持实体基础成员(不包含导航对象)

    若想使用导航对象,请使用 ISelect.ToUpdate() 方法

    Declaration
    IUpdate<T1> Where(Expression<Func<T1, bool>> exp)
    Parameters
    Type Name Description
    System.Linq.Expressions.Expression<System.Func<T1, System.Boolean>> exp

    lambda表达式条件

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    Where(String, Object)

    原生sql语法条件,Where("id = @id&quot;, new { id = 1 })

    提示:parms 参数还可以传 Dictionary<string, object>

    Declaration
    IUpdate<T1> Where(string sql, object parms = null)
    Parameters
    Type Name Description
    System.String sql

    sql语法条件

    System.Object parms

    参数

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    WhereDynamic(Object, Boolean)

    传入动态条件,如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1}

    Declaration
    IUpdate<T1> WhereDynamic(object dywhere, bool not = false)
    Parameters
    Type Name Description
    System.Object dywhere

    主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合

    System.Boolean not

    是否标识为NOT

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    WhereIf(Boolean, Expression<Func<T1, Boolean>>)

    lambda表达式条件,仅支持实体基础成员(不包含导航对象)

    若想使用导航对象,请使用 ISelect.ToUpdate() 方法

    Declaration
    IUpdate<T1> WhereIf(bool condition, Expression<Func<T1, bool>> exp)
    Parameters
    Type Name Description
    System.Boolean condition

    true 时生效

    System.Linq.Expressions.Expression<System.Func<T1, System.Boolean>> exp

    lambda表达式条件

    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    WithConnection(DbConnection)

    指定事务对象

    Declaration
    IUpdate<T1> WithConnection(DbConnection connection)
    Parameters
    Type Name Description
    System.Data.Common.DbConnection connection
    Returns
    Type Description
    IUpdate<T1>
    | Improve this Doc View Source

    WithTransaction(DbTransaction)

    指定事务对象

    Declaration
    IUpdate<T1> WithTransaction(DbTransaction transaction)
    Parameters
    Type Name Description
    System.Data.Common.DbTransaction transaction
    Returns
    Type Description
    IUpdate<T1>
    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX