Skip to content

Commit

Permalink
v0.1.1 增加选项 IsQuoteSqlName 控制是否使用 [] 或 "" 或 `` 包含数据库名称 #6
Browse files Browse the repository at this point in the history
  • Loading branch information
28810 authored and 28810 committed Feb 21, 2019
1 parent 204ab9f commit ae347d4
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion FreeSql.Repository/FreeSql.Repository.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.1.0</Version>
<Version>0.1.1</Version>
<Authors>YeXiangQin</Authors>
<Description>打造 .NETCore 最方便的 ORM,DbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion FreeSql/FreeSql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.1.0</Version>
<Version>0.1.1</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors>
<Description>打造 .NETCore 最方便的 ORM,DbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
Expand Down
11 changes: 11 additions & 0 deletions FreeSql/FreeSqlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class FreeSqlBuilder {
string _masterConnectionString;
string[] _slaveConnectionString;
bool _isAutoSyncStructure = false;
bool _isQuoteSqlName = true;
bool _isSyncStructureToLower = false;
bool _isLazyLoading = false;
Action<DbCommand> _aopCommandExecuting = null;
Expand Down Expand Up @@ -67,6 +68,15 @@ public FreeSqlBuilder UseAutoSyncStructure(bool value) {
return this;
}
/// <summary>
/// 数据库名称使用 [] 或 `` 或 "" 包含起来,取决于数据库类别
/// </summary>
/// <param name="value">true:转小写, false:不转</param>
/// <returns></returns>
public FreeSqlBuilder UseQuoteSqlName(bool value) {
_isQuoteSqlName = value;
return this;
}
/// <summary>
/// 转小写同步结构
/// </summary>
/// <param name="value">true:转小写, false:不转</param>
Expand Down Expand Up @@ -107,6 +117,7 @@ public IFreeSql Build() {
}
if (ret != null) {
ret.CodeFirst.IsAutoSyncStructure = _isAutoSyncStructure;
ret.CodeFirst.IsQuoteSqlName = _isQuoteSqlName;
ret.CodeFirst.IsSyncStructureToLower = _isSyncStructureToLower;
ret.CodeFirst.IsLazyLoading = _isLazyLoading;
var ado = ret.Ado as Internal.CommonProvider.AdoProvider;
Expand Down
4 changes: 4 additions & 0 deletions FreeSql/Interface/ICodeFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public interface ICodeFirst {
/// </summary>
bool IsAutoSyncStructure { get; set; }

/// <summary>
/// 数据库名称使用 [] 或 `` 或 "" 包含起来,取决于数据库类别
/// </summary>
bool IsQuoteSqlName { get; set; }
/// <summary>
/// 转小写同步结构
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions FreeSql/MySql/MySqlCodeFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public MySqlCodeFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression co
}

public bool IsAutoSyncStructure { get; set; } = true;
public bool IsQuoteSqlName { get; set; } = true;
public bool IsSyncStructureToLower { get; set; } = false;
public bool IsLazyLoading { get; set; } = false;

Expand Down
2 changes: 1 addition & 1 deletion FreeSql/MySql/MySqlUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal override DbParameter[] GetDbParamtersByObject(string sql, object obj) =
});

internal override string FormatSql(string sql, params object[] args) => sql?.FormatMySql(args);
internal override string QuoteSqlName(string name) => $"`{name.Trim('`').Replace(".", "`.`")}`";
internal override string QuoteSqlName(string name) => _orm.CodeFirst.IsQuoteSqlName ? $"`{name.Trim('`').Replace(".", "`.`")}`" : name;
internal override string QuoteParamterName(string name) => $"?{(_orm.CodeFirst.IsSyncStructureToLower ? name.ToLower() : name)}";
internal override string IsNull(string sql, object value) => $"ifnull({sql}, {value})";
internal override string StringConcat(string left, string right, Type leftType, Type rightType) => $"concat({left}, {right})";
Expand Down
1 change: 1 addition & 0 deletions FreeSql/Oracle/OracleCodeFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public OracleCodeFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression c
}

public bool IsAutoSyncStructure { get; set; } = true;
public bool IsQuoteSqlName { get; set; } = true;
public bool IsSyncStructureToLower { get; set; } = false;
public bool IsLazyLoading { get; set; } = false;

Expand Down
2 changes: 1 addition & 1 deletion FreeSql/Oracle/OracleUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal override DbParameter[] GetDbParamtersByObject(string sql, object obj) =
});

internal override string FormatSql(string sql, params object[] args) => sql?.FormatOracleSQL(args);
internal override string QuoteSqlName(string name) => $"\"{name.Trim('"').Replace(".", "\".\"")}\"";
internal override string QuoteSqlName(string name) => _orm.CodeFirst.IsQuoteSqlName ? $"\"{name.Trim('"').Replace(".", "\".\"")}\"" : name;
internal override string QuoteParamterName(string name) => $":{(_orm.CodeFirst.IsSyncStructureToLower ? name.ToLower() : name)}";
internal override string IsNull(string sql, object value) => $"nvl({sql}, {value})";
internal override string StringConcat(string left, string right, Type leftType, Type rightType) => $"{left} || {right}";
Expand Down
1 change: 1 addition & 0 deletions FreeSql/PostgreSQL/PostgreSQLCodeFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public PostgreSQLCodeFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpressi
}

public bool IsAutoSyncStructure { get; set; } = true;
public bool IsQuoteSqlName { get; set; } = true;
public bool IsSyncStructureToLower { get; set; } = false;
public bool IsLazyLoading { get; set; } = false;

Expand Down
2 changes: 1 addition & 1 deletion FreeSql/PostgreSQL/PostgreSQLUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ internal override DbParameter[] GetDbParamtersByObject(string sql, object obj) =
});

internal override string FormatSql(string sql, params object[] args) => sql?.FormatPostgreSQL(args);
internal override string QuoteSqlName(string name) => $"\"{name.Trim('"').Replace(".", "\".\"")}\"";
internal override string QuoteSqlName(string name) => _orm.CodeFirst.IsQuoteSqlName ? $"\"{name.Trim('"').Replace(".", "\".\"")}\"" : name;
internal override string QuoteParamterName(string name) => $"@{(_orm.CodeFirst.IsSyncStructureToLower ? name.ToLower() : name)}";
internal override string IsNull(string sql, object value) => $"coalesce({sql}, {value})";
internal override string StringConcat(string left, string right, Type leftType, Type rightType) => $"{left} || {right}";
Expand Down
1 change: 1 addition & 0 deletions FreeSql/SqlServer/SqlServerCodeFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public SqlServerCodeFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpressio
}

public bool IsAutoSyncStructure { get; set; } = true;
public bool IsQuoteSqlName { get; set; } = true;
public bool IsSyncStructureToLower { get; set; } = false;
public bool IsLazyLoading { get; set; } = false;

Expand Down
2 changes: 1 addition & 1 deletion FreeSql/SqlServer/SqlServerUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal override DbParameter[] GetDbParamtersByObject(string sql, object obj) =
});

internal override string FormatSql(string sql, params object[] args) => sql?.FormatSqlServer(args);
internal override string QuoteSqlName(string name) => $"[{name.TrimStart('[').TrimEnd(']').Replace(".", "].[")}]";
internal override string QuoteSqlName(string name) => _orm.CodeFirst.IsQuoteSqlName ? $"[{name.TrimStart('[').TrimEnd(']').Replace(".", "].[")}]" : name;
internal override string QuoteParamterName(string name) => $"@{(_orm.CodeFirst.IsSyncStructureToLower ? name.ToLower() : name)}";
internal override string IsNull(string sql, object value) => $"isnull({sql}, {value})";
internal override string StringConcat(string left, string right, Type leftType, Type rightType) => $"{(leftType.FullName == "System.String" ? left : $"cast({left} as nvarchar)")} + {(rightType.FullName == "System.String" ? right : $"cast({right} as nvarchar)")}";
Expand Down
1 change: 1 addition & 0 deletions FreeSql/Sqlite/SqliteCodeFirst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public SqliteCodeFirst(IFreeSql orm, CommonUtils commonUtils, CommonExpression c
}

public bool IsAutoSyncStructure { get; set; } = true;
public bool IsQuoteSqlName { get; set; } = true;
public bool IsSyncStructureToLower { get; set; } = false;
public bool IsLazyLoading { get; set; } = false;

Expand Down
2 changes: 1 addition & 1 deletion FreeSql/Sqlite/SqliteUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal override DbParameter[] GetDbParamtersByObject(string sql, object obj) =
});

internal override string FormatSql(string sql, params object[] args) => sql?.FormatSqlite(args);
internal override string QuoteSqlName(string name) => $"\"{name.Trim('"').Replace(".", "\".\"")}\"";
internal override string QuoteSqlName(string name) => _orm.CodeFirst.IsQuoteSqlName ? $"\"{name.Trim('"').Replace(".", "\".\"")}\"" : name;
internal override string QuoteParamterName(string name) => $"@{(_orm.CodeFirst.IsSyncStructureToLower ? name.ToLower() : name)}";
internal override string IsNull(string sql, object value) => $"ifnull({sql}, {value})";
internal override string StringConcat(string left, string right, Type leftType, Type rightType) => $"{left} || {right}";
Expand Down

0 comments on commit ae347d4

Please sign in to comment.