Search Results for

    Show / Hide Table of Contents

    Class FreeSqlBuilder

    Inheritance
    System.Object
    FreeSqlBuilder
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: FreeSql
    Assembly: FreeSql.dll
    Syntax
    public class FreeSqlBuilder

    Methods

    | Improve this Doc View Source

    Build()

    Declaration
    public IFreeSql Build()
    Returns
    Type Description
    IFreeSql
    | Improve this Doc View Source

    Build<TMark>()

    Declaration
    public IFreeSql<TMark> Build<TMark>()
    Returns
    Type Description
    IFreeSql<TMark>
    Type Parameters
    Name Description
    TMark
    | Improve this Doc View Source

    UseAdoConnectionPool(Boolean)

    使用原始连接池(ado.net、odbc、oledb)

    默认:false

    UseConnectionString 默认使用 FreeSql 连接池,有以下特点:

    • 状态不可用,断熔机制直到后台检测恢复

    • 读写分离,从库不可用,会切换其他可用从库

    • 监测连接池使用情况,fsql.Ado.Statistics

      有部分使用者不喜欢【断熔机制】,可使用此设置

    Declaration
    public FreeSqlBuilder UseAdoConnectionPool(bool value)
    Parameters
    Type Name Description
    System.Boolean value
    Returns
    Type Description
    FreeSqlBuilder
    | Improve this Doc View Source

    UseAutoSyncStructure(Boolean)

    【开发环境必备】自动同步实体结构到数据库,程序运行中检查实体表是否存在,然后创建或修改

    注意:生产环境中谨慎使用

    Declaration
    public FreeSqlBuilder UseAutoSyncStructure(bool value)
    Parameters
    Type Name Description
    System.Boolean value

    true:运行时检查自动同步结构, false:不同步结构(默认)

    Returns
    Type Description
    FreeSqlBuilder
    | Improve this Doc View Source

    UseConfigEntityFromDbFirst(Boolean)

    将数据库的主键、自增、索引设置导入,适用 DbFirst 模式,无须在实体类型上设置 [Column(IsPrimary)] 或者 ConfigEntity。此功能目前可用于 mysql/sqlserver/postgresql/oracle。

    本功能会影响 IFreeSql 首次访问的速度。

    若使用 CodeFirst 创建索引后,又直接在数据库上建了索引,若无本功能下一次 CodeFirst 迁移时数据库上创建的索引将被删除

    Declaration
    public FreeSqlBuilder UseConfigEntityFromDbFirst(bool value)
    Parameters
    Type Name Description
    System.Boolean value
    Returns
    Type Description
    FreeSqlBuilder
    | Improve this Doc View Source

    UseConnectionFactory(DataType, Func<DbConnection>, Type)

    使用自定义数据库连接对象(放弃内置对象连接池技术)

    Declaration
    public FreeSqlBuilder UseConnectionFactory(DataType dataType, Func<DbConnection> connectionFactory, Type providerType = null)
    Parameters
    Type Name Description
    DataType dataType

    数据库类型

    System.Func<System.Data.Common.DbConnection> connectionFactory

    数据库连接对象创建器

    System.Type providerType

    提供者的类型,一般不需要指定,如果一直提示“缺少 FreeSql 数据库实现包:FreeSql.Provider.MySql.dll,可前往 nuget 下载”的错误,说明反射获取不到类型,此时该参数可排上用场

    例如:typeof(FreeSql.SqlServer.SqlServerProvider<>)

    Returns
    Type Description
    FreeSqlBuilder
    | Improve this Doc View Source

    UseConnectionString(DataType, String, Type)

    使用连接串(推荐)

    Declaration
    public FreeSqlBuilder UseConnectionString(DataType dataType, string connectionString, Type providerType = null)
    Parameters
    Type Name Description
    DataType dataType

    数据库类型

    System.String connectionString

    数据库连接串

    System.Type providerType

    提供者的类型,一般不需要指定,如果一直提示“缺少 FreeSql 数据库实现包:FreeSql.Provider.MySql.dll,可前往 nuget 下载”的错误,说明反射获取不到类型,此时该参数可排上用场

    例如:typeof(FreeSql.SqlServer.SqlServerProvider<>)

    Returns
    Type Description
    FreeSqlBuilder
    | Improve this Doc View Source

    UseExitAutoDisposePool(Boolean)

    监听 AppDomain.CurrentDomain.ProcessExit/Console.CancelKeyPress 事件自动释放连接池

    默认值: true

    Declaration
    public FreeSqlBuilder UseExitAutoDisposePool(bool value)
    Parameters
    Type Name Description
    System.Boolean value
    Returns
    Type Description
    FreeSqlBuilder
    | Improve this Doc View Source

    UseGenerateCommandParameterWithLambda(Boolean)

    是否生成命令参数化执行,针对 lambda 表达式解析

    注意:常量不会参数化,变量才会做参数化

    var id = 100; fsql.Select<T>().Where(a => a.id == id) 会参数化

    fsql.Select<T>().Where(a => a.id == 100) 不会参数化

    Declaration
    public FreeSqlBuilder UseGenerateCommandParameterWithLambda(bool value)
    Parameters
    Type Name Description
    System.Boolean value
    Returns
    Type Description
    FreeSqlBuilder
    | Improve this Doc View Source

    UseLazyLoading(Boolean)

    延时加载导航属性对象,导航属性需要声明 virtual

    Declaration
    public FreeSqlBuilder UseLazyLoading(bool value)
    Parameters
    Type Name Description
    System.Boolean value
    Returns
    Type Description
    FreeSqlBuilder
    | Improve this Doc View Source

    UseMappingPriority(MappingPriorityType, MappingPriorityType, MappingPriorityType)

    指定映射优先级

    例如表名:实体类名 < Aop < FluentApi < Attribute < AsTable

    事件 Aop -------> fsql.Aop.ConfigEntity/fsql.Aop.ConfigEntityProperty

    方法 FluentApi -> fsql.CodeFirst.ConfigEntity/fsql.CodeFirst.Entity

    特性 Attribute -> [Table(Name = xxx, ...)]

    -----------------------------------------------------------------------------

    默认规则:关于映射优先级,Attribute 可以更直观排查问题,即使任何地方使用 FluentApi/Aop 设置 TableName 都不生效。

    调整规则:UseMappingPriority(Attribute, FluentApi, Aop)

    实体类名 < Attribute < FluentApi < Aop < AsTable

    Declaration
    public FreeSqlBuilder UseMappingPriority(MappingPriorityType mappingType1, MappingPriorityType mappingType2, MappingPriorityType mappingType3)
    Parameters
    Type Name Description
    MappingPriorityType mappingType1
    MappingPriorityType mappingType2
    MappingPriorityType mappingType3
    Returns
    Type Description
    FreeSqlBuilder
    Exceptions
    Type Condition
    System.ArgumentException
    | Improve this Doc View Source

    UseMonitorCommand(Action<DbCommand>, Action<DbCommand, String>)

    监视数据库命令对象

    Declaration
    public FreeSqlBuilder UseMonitorCommand(Action<DbCommand> executing, Action<DbCommand, string> executed = null)
    Parameters
    Type Name Description
    System.Action<System.Data.Common.DbCommand> executing

    执行前

    System.Action<System.Data.Common.DbCommand, System.String> executed

    执行后,可监视执行性能

    Returns
    Type Description
    FreeSqlBuilder
    | Improve this Doc View Source

    UseNameConvert(NameConvertType)

    实体类名 -> 数据库表名,命名转换(类名、属性名都生效)

    优先级小于 [Column(Name = "xxx")]

    Declaration
    public FreeSqlBuilder UseNameConvert(NameConvertType convertType)
    Parameters
    Type Name Description
    NameConvertType convertType
    Returns
    Type Description
    FreeSqlBuilder
    | Improve this Doc View Source

    UseNoneCommandParameter(Boolean)

    不使用命令参数化执行,针对 Insert/Update,也可临时使用 IInsert/IUpdate.NoneParameter()

    Declaration
    public FreeSqlBuilder UseNoneCommandParameter(bool value)
    Parameters
    Type Name Description
    System.Boolean value
    Returns
    Type Description
    FreeSqlBuilder
    | Improve this Doc View Source

    UseQuoteSqlName(Boolean)

    SQL名称是否使用 [] `` ""

    true: SELECT .. FROM [table]

    false: SELECT .. FROM table

    Declaration
    public FreeSqlBuilder UseQuoteSqlName(bool value)
    Parameters
    Type Name Description
    System.Boolean value
    Returns
    Type Description
    FreeSqlBuilder
    | Improve this Doc View Source

    UseSlave(String[])

    使用从数据库,支持多个

    Declaration
    public FreeSqlBuilder UseSlave(params string[] slaveConnectionString)
    Parameters
    Type Name Description
    System.String[] slaveConnectionString

    从数据库连接串

    Returns
    Type Description
    FreeSqlBuilder
    | Improve this Doc View Source

    UseSlaveWeight(Int32[])

    Declaration
    public FreeSqlBuilder UseSlaveWeight(params int[] slaveWeights)
    Parameters
    Type Name Description
    System.Int32[] slaveWeights
    Returns
    Type Description
    FreeSqlBuilder
    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX