mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
v0.1.5
- 增加 IsSyncStructureToUpper 参数,以便适应 Oracle 大小写使用习惯; - FreeSql.Repository 增加 GuidRepository 类,适用 Insert 方法无须返回插入的数据; - FreeSql.Repository 增加 IFreeSql 扩展方法 GetRepository、GetGuidRepository;
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>0.1.4</Version>
|
||||
<Version>0.1.5</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>打造 .NETCore 最方便的 ORM,DbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
|
||||
|
@ -13,8 +13,8 @@ namespace FreeSql {
|
||||
string _masterConnectionString;
|
||||
string[] _slaveConnectionString;
|
||||
bool _isAutoSyncStructure = false;
|
||||
bool _isQuoteSqlName = true;
|
||||
bool _isSyncStructureToLower = false;
|
||||
bool _isSyncStructureToUpper = false;
|
||||
bool _isLazyLoading = false;
|
||||
Action<DbCommand> _aopCommandExecuting = null;
|
||||
Action<DbCommand, string> _aopCommandExecuted = null;
|
||||
@ -68,15 +68,6 @@ namespace FreeSql {
|
||||
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>
|
||||
@ -86,6 +77,15 @@ namespace FreeSql {
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// 转大写同步结构
|
||||
/// </summary>
|
||||
/// <param name="value">true:转大写, false:不转</param>
|
||||
/// <returns></returns>
|
||||
public FreeSqlBuilder UseSyncStructureToUpper(bool value) {
|
||||
_isSyncStructureToUpper = value;
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// 延时加载导航属性对象,导航属性需要声明 virtual
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
@ -117,8 +117,9 @@ namespace FreeSql {
|
||||
}
|
||||
if (ret != null) {
|
||||
ret.CodeFirst.IsAutoSyncStructure = _isAutoSyncStructure;
|
||||
ret.CodeFirst.IsQuoteSqlName = _isQuoteSqlName;
|
||||
|
||||
ret.CodeFirst.IsSyncStructureToLower = _isSyncStructureToLower;
|
||||
ret.CodeFirst.IsSyncStructureToUpper = _isSyncStructureToUpper;
|
||||
ret.CodeFirst.IsLazyLoading = _isLazyLoading;
|
||||
var ado = ret.Ado as Internal.CommonProvider.AdoProvider;
|
||||
ado.AopCommandExecuting += _aopCommandExecuting;
|
||||
|
@ -9,15 +9,15 @@ namespace FreeSql {
|
||||
/// </summary>
|
||||
bool IsAutoSyncStructure { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据库名称使用 [] 或 `` 或 "" 包含起来,取决于数据库类别
|
||||
/// </summary>
|
||||
bool IsQuoteSqlName { get; set; }
|
||||
/// <summary>
|
||||
/// 转小写同步结构
|
||||
/// </summary>
|
||||
bool IsSyncStructureToLower { get; set; }
|
||||
/// <summary>
|
||||
/// 转大写同步结构
|
||||
/// </summary>
|
||||
bool IsSyncStructureToUpper { get; set; }
|
||||
/// <summary>
|
||||
/// 延时加载导航属性对象,导航属性需要声明 virtual
|
||||
/// </summary>
|
||||
bool IsLazyLoading { get; set; }
|
||||
|
@ -41,6 +41,10 @@ namespace FreeSql.Internal {
|
||||
trytb.DbName = trytb.DbName.ToLower();
|
||||
trytb.DbOldName = trytb.DbOldName?.ToLower();
|
||||
}
|
||||
if (common.CodeFirst.IsSyncStructureToUpper) {
|
||||
trytb.DbName = trytb.DbName.ToUpper();
|
||||
trytb.DbOldName = trytb.DbOldName?.ToUpper();
|
||||
}
|
||||
trytb.SelectFilter = tbattr?.SelectFilter;
|
||||
var propsLazy = new List<(PropertyInfo, bool, bool)>();
|
||||
foreach (var p in trytb.Properties.Values) {
|
||||
@ -73,6 +77,7 @@ namespace FreeSql.Internal {
|
||||
if (colattr.DbType?.Contains("NOT NULL") == true) colattr.IsNullable = false;
|
||||
if (string.IsNullOrEmpty(colattr.Name)) colattr.Name = p.Name;
|
||||
if (common.CodeFirst.IsSyncStructureToLower) colattr.Name = colattr.Name.ToLower();
|
||||
if (common.CodeFirst.IsSyncStructureToUpper) colattr.Name = colattr.Name.ToUpper();
|
||||
|
||||
if ((colattr.IsNullable != true || colattr.IsIdentity == true || colattr.IsPrimary == true) && colattr.DbType.Contains("NOT NULL") == false) {
|
||||
colattr.IsNullable = false;
|
||||
|
@ -24,8 +24,8 @@ namespace FreeSql.MySql {
|
||||
}
|
||||
|
||||
public bool IsAutoSyncStructure { get; set; } = true;
|
||||
public bool IsQuoteSqlName { get; set; } = true;
|
||||
public bool IsSyncStructureToLower { get; set; } = false;
|
||||
public bool IsSyncStructureToUpper { get; set; } = false;
|
||||
public bool IsLazyLoading { get; set; } = false;
|
||||
|
||||
static object _dicCsToDbLock = new object();
|
||||
|
@ -42,7 +42,7 @@ namespace FreeSql.MySql {
|
||||
});
|
||||
|
||||
internal override string FormatSql(string sql, params object[] args) => sql?.FormatMySql(args);
|
||||
internal override string QuoteSqlName(string name) => _orm.CodeFirst.IsQuoteSqlName ? $"`{name.Trim('`').Replace(".", "`.`")}`" : name;
|
||||
internal override string QuoteSqlName(string name) => $"`{name.Trim('`').Replace(".", "`.`")}`";
|
||||
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})";
|
||||
|
@ -26,6 +26,7 @@ namespace FreeSql.Oracle {
|
||||
public bool IsAutoSyncStructure { get; set; } = true;
|
||||
public bool IsQuoteSqlName { get; set; } = true;
|
||||
public bool IsSyncStructureToLower { get; set; } = false;
|
||||
public bool IsSyncStructureToUpper { get; set; } = false;
|
||||
public bool IsLazyLoading { get; set; } = false;
|
||||
|
||||
static object _dicCsToDbLock = new object();
|
||||
|
@ -38,7 +38,7 @@ namespace FreeSql.Oracle {
|
||||
});
|
||||
|
||||
internal override string FormatSql(string sql, params object[] args) => sql?.FormatOracleSQL(args);
|
||||
internal override string QuoteSqlName(string name) => _orm.CodeFirst.IsQuoteSqlName ? $"\"{name.Trim('"').Replace(".", "\".\"")}\"" : name;
|
||||
internal override string QuoteSqlName(string name) => $"\"{name.Trim('"').Replace(".", "\".\"")}\"";
|
||||
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}";
|
||||
|
@ -29,8 +29,8 @@ namespace FreeSql.PostgreSQL {
|
||||
}
|
||||
|
||||
public bool IsAutoSyncStructure { get; set; } = true;
|
||||
public bool IsQuoteSqlName { get; set; } = true;
|
||||
public bool IsSyncStructureToLower { get; set; } = false;
|
||||
public bool IsSyncStructureToUpper { get; set; } = false;
|
||||
public bool IsLazyLoading { get; set; } = false;
|
||||
|
||||
static object _dicCsToDbLock = new object();
|
||||
|
@ -94,7 +94,7 @@ namespace FreeSql.PostgreSQL {
|
||||
});
|
||||
|
||||
internal override string FormatSql(string sql, params object[] args) => sql?.FormatPostgreSQL(args);
|
||||
internal override string QuoteSqlName(string name) => _orm.CodeFirst.IsQuoteSqlName ? $"\"{name.Trim('"').Replace(".", "\".\"")}\"" : name;
|
||||
internal override string QuoteSqlName(string name) => $"\"{name.Trim('"').Replace(".", "\".\"")}\"";
|
||||
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}";
|
||||
|
@ -23,8 +23,8 @@ namespace FreeSql.SqlServer {
|
||||
}
|
||||
|
||||
public bool IsAutoSyncStructure { get; set; } = true;
|
||||
public bool IsQuoteSqlName { get; set; } = true;
|
||||
public bool IsSyncStructureToLower { get; set; } = false;
|
||||
public bool IsSyncStructureToUpper { get; set; } = false;
|
||||
public bool IsLazyLoading { get; set; } = false;
|
||||
|
||||
static object _dicCsToDbLock = new object();
|
||||
|
@ -34,7 +34,7 @@ namespace FreeSql.SqlServer {
|
||||
});
|
||||
|
||||
internal override string FormatSql(string sql, params object[] args) => sql?.FormatSqlServer(args);
|
||||
internal override string QuoteSqlName(string name) => _orm.CodeFirst.IsQuoteSqlName ? $"[{name.TrimStart('[').TrimEnd(']').Replace(".", "].[")}]" : name;
|
||||
internal override string QuoteSqlName(string name) => $"[{name.TrimStart('[').TrimEnd(']').Replace(".", "].[")}]";
|
||||
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)")}";
|
||||
|
@ -23,8 +23,8 @@ namespace FreeSql.Sqlite {
|
||||
}
|
||||
|
||||
public bool IsAutoSyncStructure { get; set; } = true;
|
||||
public bool IsQuoteSqlName { get; set; } = true;
|
||||
public bool IsSyncStructureToLower { get; set; } = false;
|
||||
public bool IsSyncStructureToUpper { get; set; } = false;
|
||||
public bool IsLazyLoading { get; set; } = false;
|
||||
|
||||
static object _dicCsToDbLock = new object();
|
||||
|
@ -53,7 +53,7 @@ namespace FreeSql.Sqlite {
|
||||
});
|
||||
|
||||
internal override string FormatSql(string sql, params object[] args) => sql?.FormatSqlite(args);
|
||||
internal override string QuoteSqlName(string name) => _orm.CodeFirst.IsQuoteSqlName ? $"\"{name.Trim('"').Replace(".", "\".\"")}\"" : name;
|
||||
internal override string QuoteSqlName(string name) => $"\"{name.Trim('"').Replace(".", "\".\"")}\"";
|
||||
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}";
|
||||
|
Reference in New Issue
Block a user