#694 Exception信息 国际化 多语言

This commit is contained in:
igeekfan
2022-05-20 02:52:58 +08:00
parent a7b40e9a5a
commit 83a4bb8039
79 changed files with 5343 additions and 398 deletions

View File

@@ -2,7 +2,6 @@
using FreeSql.Internal.ObjectPool;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
@@ -631,7 +630,7 @@ namespace FreeSql.Internal.CommonProvider
ReturnConnection(pool, conn, ex); //pool.Return(conn, ex);
if (IsTracePerformance) logtxt.Append("Pool.Return: ").Append(DateTime.Now.Subtract(logtxt_dt).TotalMilliseconds).Append("ms Total: ").Append(DateTime.Now.Subtract(dt).TotalMilliseconds).Append("ms");
}
LoggerException(pool, pc, new Exception($"连接失败,准备切换其他可用服务器"), dt, logtxt, false);
LoggerException(pool, pc, new Exception(CoreStrings.Connection_Failed_Switch_Servers), dt, logtxt, false);
pc.cmd.Parameters.Clear();
if (DataType == DataType.Sqlite) pc.cmd.Dispose();
ExecuteReaderMultiple(multipleResult, connection, transaction, fetchHandler, schemaHandler, cmdType, cmdText, cmdTimeout, cmdParms);

View File

@@ -537,7 +537,7 @@ namespace FreeSql.Internal.CommonProvider
ReturnConnection(pool, conn, ex); //pool.Return(conn, ex);
if (IsTracePerformance) logtxt.Append("Pool.Return: ").Append(DateTime.Now.Subtract(logtxt_dt).TotalMilliseconds).Append("ms Total: ").Append(DateTime.Now.Subtract(dt).TotalMilliseconds).Append("ms");
}
LoggerException(pool, pc, new Exception($"连接失败,准备切换其他可用服务器"), dt, logtxt, false);
LoggerException(pool, pc, new Exception(CoreStrings.Connection_Failed_Switch_Servers), dt, logtxt, false);
pc.cmd.Parameters.Clear();
if (DataType == DataType.Sqlite) pc.cmd.Dispose();
await ExecuteReaderMultipleAsync(multipleResult, connection, transaction, fetchHandler, schemaHandler, cmdType, cmdText, cmdTimeout, cmdParms, cancellationToken);

View File

@@ -78,7 +78,7 @@ namespace FreeSql.Internal.CommonProvider
_trans.TryRemove(tran.Connection.LastGetThreadId, out var oldtran);
Exception ex = null;
if (string.IsNullOrEmpty(remark)) remark = isCommit ? "提交" : "回滚";
if (string.IsNullOrEmpty(remark)) remark = isCommit ? CoreStrings.Commit : CoreStrings.RollBack;
try
{
if (tran.Transaction.Connection != null) //用户自行 Commit、Rollback

View File

@@ -18,23 +18,23 @@ namespace FreeSql.Internal.CommonProvider
public IInsert<T1> Insert<T1>() where T1 : class => CreateInsertProvider<T1>();
public IInsert<T1> Insert<T1>(T1 source) where T1 : class
{
if (typeof(T1) == typeof(Dictionary<string, object>)) throw new Exception("请使用 fsql.InsertDict(dict) 方法插入字典数据");
if (typeof(T1) == typeof(Dictionary<string, object>)) throw new Exception(CoreStrings.Use_InsertDict_Method);
return this.Insert<T1>().AppendData(source);
}
public IInsert<T1> Insert<T1>(T1[] source) where T1 : class
{
if (typeof(T1) == typeof(Dictionary<string, object>)) throw new Exception("请使用 fsql.InsertDict(dict) 方法插入字典数据");
if (typeof(T1) == typeof(Dictionary<string, object>)) throw new Exception(CoreStrings.Use_InsertDict_Method);
return this.Insert<T1>().AppendData(source);
}
public IInsert<T1> Insert<T1>(List<T1> source) where T1 : class
{
if (typeof(T1) == typeof(Dictionary<string, object>)) throw new Exception("请使用 fsql.InsertDict(dict) 方法插入字典数据");
if (typeof(T1) == typeof(Dictionary<string, object>)) throw new Exception(CoreStrings.Use_InsertDict_Method);
return this.Insert<T1>().AppendData(source);
}
public IInsert<T1> Insert<T1>(IEnumerable<T1> source) where T1 : class
{
if (typeof(T1) == typeof(Dictionary<string, object>)) throw new Exception("请使用 fsql.InsertDict(dict) 方法插入字典数据");
if (typeof(T1) == typeof(Dictionary<string, object>)) throw new Exception(CoreStrings.Use_InsertDict_Method);
return this.Insert<T1>().AppendData(source);
}
public IUpdate<T1> Update<T1>() where T1 : class => CreateUpdateProvider<T1>(null);

View File

@@ -160,10 +160,10 @@ namespace FreeSql.Internal.CommonProvider
}
public IDelete<T1> AsType(Type entityType)
{
if (entityType == typeof(object)) throw new Exception("IDelete.AsType 参数不支持指定为 object");
if (entityType == typeof(object)) throw new Exception(CoreStrings.TypeAsType_NotSupport_Object("IDelete"));
if (entityType == _table.Type) return this;
var newtb = _commonUtils.GetTableByEntity(entityType);
_table = newtb ?? throw new Exception("IDelete.AsType 参数错误,请传入正确的实体类型");
_table = newtb ?? throw new Exception(CoreStrings.Type_AsType_Parameter_Error("IDelete"));
if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(entityType);
return this;
}

View File

@@ -38,7 +38,7 @@ namespace FreeSql.Internal.CommonProvider
_commonExpression = commonExpression;
_table = _commonUtils.GetTableByEntity(typeof(T1));
if (_table == null && typeof(T1) != typeof(Dictionary<string, object>))
throw new Exception($"InsertOrUpdate<>的泛型参数 不支持 {typeof(T1)},请传递您的实体类");
throw new Exception(CoreStrings.InsertOrUpdate_NotSuport_Generic_UseEntity(typeof(T1)));
if (_orm.CodeFirst.IsAutoSyncStructure && typeof(T1) != typeof(object)) _orm.CodeFirst.SyncStructure<T1>();
IdentityColumn = _table?.Primarys.Where(a => a.Attribute.IsIdentity).FirstOrDefault();
}
@@ -88,7 +88,7 @@ namespace FreeSql.Internal.CommonProvider
{
if (data == null || table == null) return;
if (typeof(T1) == typeof(object) && new[] { table.Type, table.TypeLazy }.Contains(data.GetType()) == false)
throw new Exception($"操作的数据类型({data.GetType().DisplayCsharp()}) 与 AsType({table.Type.DisplayCsharp()}) 不一致,请检查。");
throw new Exception(CoreStrings.DataType_AsType_Inconsistent(data.GetType().DisplayCsharp(), table.Type.DisplayCsharp()));
if (orm.Aop.AuditValueHandler == null) return;
foreach (var col in table.Columns.Values)
{
@@ -157,10 +157,10 @@ namespace FreeSql.Internal.CommonProvider
}
public IInsertOrUpdate<T1> AsType(Type entityType)
{
if (entityType == typeof(object)) throw new Exception("IInsertOrUpdate.AsType 参数不支持指定为 object");
if (entityType == typeof(object)) throw new Exception(CoreStrings.TypeAsType_NotSupport_Object("IInsertOrUpdate"));
if (entityType == _table.Type) return this;
var newtb = _commonUtils.GetTableByEntity(entityType);
_table = newtb ?? throw new Exception("IInsertOrUpdate.AsType 参数错误,请传入正确的实体类型");
_table = newtb ?? throw new Exception(CoreStrings.Type_AsType_Parameter_Error("IInsertOrUpdate"));
if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(entityType);
IdentityColumn = _table.Primarys.Where(a => a.Attribute.IsIdentity).FirstOrDefault();
return this;
@@ -267,7 +267,7 @@ namespace FreeSql.Internal.CommonProvider
_SplitSourceByIdentityValueIsNullFlag = 1;
foreach (var tmpsource in ss.Item1)
{
_source = tmpsource;
_source = tmpsource;
affrows += this.RawExecuteAffrows();
}
_SplitSourceByIdentityValueIsNullFlag = 2;
@@ -299,12 +299,12 @@ namespace FreeSql.Internal.CommonProvider
affrows += this.RawExecuteAffrows();
}
_transaction.Commit();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "提交", null));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
}
catch (Exception ex)
{
_transaction.Rollback();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "回滚", ex));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
throw;
}
_transaction = null;
@@ -417,12 +417,12 @@ namespace FreeSql.Internal.CommonProvider
affrows += await this.RawExecuteAffrowsAsync(cancellationToken);
}
_transaction.Commit();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "提交", null));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
}
catch (Exception ex)
{
_transaction.Rollback();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "回滚", ex));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
throw;
}
_transaction = null;

View File

@@ -161,7 +161,7 @@ namespace FreeSql.Internal.CommonProvider
{
if (data == null || table == null) return;
if (typeof(T1) == typeof(object) && new[] { table.Type, table.TypeLazy }.Contains(data.GetType()) == false)
throw new Exception($"操作的数据类型({data.GetType().DisplayCsharp()}) 与 AsType({table.Type.DisplayCsharp()}) 不一致,请检查。");
throw new Exception(CoreStrings.DataType_AsType_Inconsistent(data.GetType().DisplayCsharp(), table.Type.DisplayCsharp()));
foreach (var col in table.Columns.Values)
{
object val = col.GetValue(data);
@@ -281,7 +281,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
using (var conn = _orm.Ado.MasterPool.Get())
{
_transaction = conn.Value.BeginTransaction();
@@ -296,12 +296,12 @@ namespace FreeSql.Internal.CommonProvider
ret += this.RawExecuteAffrows();
}
_transaction.Commit();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "提交", null));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
}
catch (Exception ex)
{
_transaction.Rollback();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "回滚", ex));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
throw;
}
_transaction = null;
@@ -361,7 +361,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
using (var conn = _orm.Ado.MasterPool.Get())
{
_transaction = conn.Value.BeginTransaction();
@@ -377,12 +377,12 @@ namespace FreeSql.Internal.CommonProvider
else ret = this.RawExecuteIdentity();
}
_transaction.Commit();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "提交", null));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
}
catch (Exception ex)
{
_transaction.Rollback();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "回滚", ex));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
throw;
}
_transaction = null;
@@ -441,7 +441,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
using (var conn = _orm.Ado.MasterPool.Get())
{
_transaction = conn.Value.BeginTransaction();
@@ -456,12 +456,12 @@ namespace FreeSql.Internal.CommonProvider
ret.AddRange(this.RawExecuteInserted());
}
_transaction.Commit();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "提交", null));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
}
catch (Exception ex)
{
_transaction.Rollback();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "回滚", ex));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
throw;
}
_transaction = null;
@@ -571,11 +571,11 @@ namespace FreeSql.Internal.CommonProvider
}
public IInsert<T1> AsType(Type entityType)
{
if (entityType == typeof(object)) throw new Exception("IInsert.AsType 参数不支持指定为 object");
if (entityType == typeof(object)) throw new Exception(CoreStrings.TypeAsType_NotSupport_Object("IInsert"));
if (entityType == typeof(T1)) return this;
if (entityType == _table.Type) return this;
var newtb = _commonUtils.GetTableByEntity(entityType);
_table = newtb ?? throw new Exception("IInsert.AsType 参数错误,请传入正确的实体类型");
_table = newtb ?? throw new Exception(CoreStrings.Type_AsType_Parameter_Error("IInsert"));
if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(entityType);
IgnoreCanInsert();
return this;

View File

@@ -55,7 +55,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
using (var conn = await _orm.Ado.MasterPool.GetAsync())
{
_transaction = conn.Value.BeginTransaction();
@@ -70,12 +70,12 @@ namespace FreeSql.Internal.CommonProvider
ret += await this.RawExecuteAffrowsAsync(cancellationToken);
}
_transaction.Commit();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "提交", null));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
}
catch (Exception ex)
{
_transaction.Rollback();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "回滚", ex));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
throw;
}
_transaction = null;
@@ -135,7 +135,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
using (var conn = await _orm.Ado.MasterPool.GetAsync())
{
_transaction = conn.Value.BeginTransaction();
@@ -151,12 +151,12 @@ namespace FreeSql.Internal.CommonProvider
else ret = await this.RawExecuteIdentityAsync(cancellationToken);
}
_transaction.Commit();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "提交", null));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
}
catch (Exception ex)
{
_transaction.Rollback();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "回滚", ex));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
throw;
}
_transaction = null;
@@ -215,7 +215,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
using (var conn = await _orm.Ado.MasterPool.GetAsync())
{
_transaction = conn.Value.BeginTransaction();
@@ -230,12 +230,12 @@ namespace FreeSql.Internal.CommonProvider
ret.AddRange(await this.RawExecuteInsertedAsync(cancellationToken));
}
_transaction.Commit();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "提交", null));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
}
catch (Exception ex)
{
_transaction.Rollback();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "回滚", ex));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
throw;
}
_transaction = null;

View File

@@ -144,7 +144,7 @@ namespace FreeSql.Internal.CommonProvider
break;
}
}
if (exp == null) throw new Exception($"无法匹配 {property}");
if (exp == null) throw new Exception(CoreStrings.Cannot_Match_Property(property));
}
else
{
@@ -160,7 +160,7 @@ namespace FreeSql.Internal.CommonProvider
{
var tmp1 = field[x];
if (_commonUtils.GetTableByEntity(currentType).Properties.TryGetValue(tmp1, out var prop) == false)
throw new ArgumentException($"{currentType.DisplayCsharp()} 无法找到属性名 {tmp1}");
throw new ArgumentException($"{currentType.DisplayCsharp()} {CoreStrings.NotFound_PropertyName(tmp1)}");
currentType = prop.PropertyType;
currentExp = Expression.MakeMemberAccess(currentExp, prop);
}
@@ -176,7 +176,7 @@ namespace FreeSql.Internal.CommonProvider
public static MethodInfo GetMethodEnumerable(string methodName) => MethodEnumerableDic.GetOrAdd(methodName, et =>
{
var methods = typeof(Enumerable).GetMethods().Where(a => a.Name == et);
if (et == "Select")
if (et == "Select")
return methods.Where(a => a.GetParameters()[1].ParameterType.GetGenericTypeDefinition() == typeof(Func<,>)).FirstOrDefault();
return methods.FirstOrDefault();
});
@@ -254,7 +254,7 @@ namespace FreeSql.Internal.CommonProvider
}
public TSelect RightJoin(Expression<Func<T1, bool>> exp)
{
if (exp == null) return this as TSelect;
if (exp == null) return this as TSelect;
_tables[0].Parameter = exp.Parameters[0];
return this.InternalJoin(exp?.Body, SelectTableInfoType.RightJoin);
}
@@ -402,7 +402,7 @@ namespace FreeSql.Internal.CommonProvider
}
public IDelete<T1> ToDelete()
{
if (_tables[0].Table.Primarys.Any() == false) throw new Exception($"ToDelete 功能要求实体类 {_tables[0].Table.CsName} 必须有主键");
if (_tables[0].Table.Primarys.Any() == false) throw new Exception(CoreStrings.Entity_Must_Primary_Key("ToDelete", _tables[0].Table.CsName));
var del = (_orm as BaseDbProvider).CreateDeleteProvider<T1>(null) as DeleteProvider<T1>;
if (_tables[0].Table.Type != typeof(T1)) del.AsType(_tables[0].Table.Type);
if (_params.Any()) del._params = new List<DbParameter>(_params.ToArray());
@@ -436,7 +436,7 @@ namespace FreeSql.Internal.CommonProvider
}
public IUpdate<T1> ToUpdate()
{
if (_tables[0].Table.Primarys.Any() == false) throw new Exception($"ToUpdate 功能要求实体类 {_tables[0].Table.CsName} 必须有主键");
if (_tables[0].Table.Primarys.Any() == false) throw new Exception(CoreStrings.Entity_Must_Primary_Key("ToUpdate", _tables[0].Table.CsName));
var upd = (_orm as BaseDbProvider).CreateUpdateProvider<T1>(null) as UpdateProvider<T1>;
if (_tables[0].Table.Type != typeof(T1)) upd.AsType(_tables[0].Table.Type);
if (_params.Any()) upd._params = new List<DbParameter>(_params.ToArray());
@@ -472,7 +472,7 @@ namespace FreeSql.Internal.CommonProvider
protected List<Dictionary<Type, string>> GetTableRuleUnions()
{
var unions = new List<Dictionary<Type, string>>();
var trs = _tableRules.Any() ? _tableRules : new List<Func<Type, string, string>>(new [] { new Func<Type, string, string>((type, oldname) => null) });
var trs = _tableRules.Any() ? _tableRules : new List<Func<Type, string, string>>(new[] { new Func<Type, string, string>((type, oldname) => null) });
if (trs.Count == 1 && _tables.Any(a => a.Table.AsTableImpl != null && string.IsNullOrWhiteSpace(trs[0](a.Table.Type, a.Table.DbName)) == true))
{
@@ -571,10 +571,10 @@ namespace FreeSql.Internal.CommonProvider
}
public TSelect AsType(Type entityType)
{
if (entityType == typeof(object)) throw new Exception("ISelect.AsType 参数不支持指定为 object");
if (entityType == typeof(object)) throw new Exception(CoreStrings.TypeAsType_NotSupport_Object("ISelect"));
if (entityType == _tables[0].Table.Type) return this as TSelect;
var newtb = _commonUtils.GetTableByEntity(entityType);
_tables[0].Table = newtb ?? throw new Exception("ISelect.AsType 参数错误,请传入正确的实体类型");
_tables[0].Table = newtb ?? throw new Exception(CoreStrings.Type_AsType_Parameter_Error("ISelect"));
if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(entityType);
return this as TSelect;
}
@@ -619,14 +619,14 @@ namespace FreeSql.Internal.CommonProvider
{
case DynamicFilterOperator.Custom:
var fiValueCustomArray = fi.Field?.ToString().Split(new[] { ' ' }, 2);
if (fiValueCustomArray.Length != 2) throw new ArgumentException("Custom 要求 Field 应该空格分割,并且长度为 2格式{静态方法名}{空格}{反射信息}");
if (string.IsNullOrWhiteSpace(fiValueCustomArray[0])) throw new ArgumentException("Custom {静态方法名}不能为空,格式:{静态方法名}{空格}{反射信息}");
if (string.IsNullOrWhiteSpace(fiValueCustomArray[1])) throw new ArgumentException("Custom {反射信息}不能为空,格式:{静态方法名}{空格}{反射信息}");
if (fiValueCustomArray.Length != 2) throw new ArgumentException(CoreStrings.CustomFieldSeparatedBySpaces);
if (string.IsNullOrWhiteSpace(fiValueCustomArray[0])) throw new ArgumentException(CoreStrings.Custom_StaticMethodName_IsNotNull);
if (string.IsNullOrWhiteSpace(fiValueCustomArray[1])) throw new ArgumentException(CoreStrings.Custom_Reflection_IsNotNull);
var fiValue1Type = Type.GetType(fiValueCustomArray[1]);
if (fiValue1Type == null) throw new ArgumentException($"Custom 找不到对应的{{反射信息}}{fiValueCustomArray[1]}");
if (fiValue1Type == null) throw new ArgumentException(CoreStrings.NotFound_Reflection(fiValueCustomArray[1]));
var fiValue0Method = fiValue1Type.GetMethod(fiValueCustomArray[0], new Type[] { typeof(string) });
if (fiValue0Method == null) throw new ArgumentException($"Custom 找不到对应的{{静态方法名}}{fiValueCustomArray[0]}");
if (MethodIsDynamicFilterCustomAttribute(fiValue0Method) == false) throw new ArgumentException($"Custom 对应的{{静态方法名}}{fiValueCustomArray[0]} 未设置 [DynamicFilterCustomAttribute] 特性");
if (fiValue0Method == null) throw new ArgumentException(CoreStrings.NotFound_Static_MethodName(fiValueCustomArray[0]));
if (MethodIsDynamicFilterCustomAttribute(fiValue0Method) == false) throw new ArgumentException(CoreStrings.Custom_StaticMethodName_NotSet_DynamicFilterCustom(fiValueCustomArray[0]));
var fiValue0MethodReturn = fiValue0Method?.Invoke(null, new object[] { fi.Value?.ToString() })?.ToString();
exp = Expression.Call(typeof(SqlExt).GetMethod("InternalRawSql", BindingFlags.NonPublic | BindingFlags.Static), Expression.Constant(fiValue0MethodReturn, typeof(string)));
break;
@@ -664,20 +664,20 @@ namespace FreeSql.Internal.CommonProvider
case DynamicFilterOperator.LessThanOrEqual: exp = Expression.Call(typeof(SqlExt).GetMethod("LessThanOrEqual").MakeGenericMethod(exp.Type), exp, Expression.Constant(Utils.GetDataReaderValue(exp.Type, fi.Value?.ToString()), exp.Type)); break;
case DynamicFilterOperator.Range:
var fiValueRangeArray = getFiListValue();
if (fiValueRangeArray.Length != 2) throw new ArgumentException($"Range 要求 Value 应该逗号分割,并且长度为 2");
if (fiValueRangeArray.Length != 2) throw new ArgumentException(CoreStrings.Range_Comma_Separateda_By2Char);
exp = Expression.AndAlso(
Expression.GreaterThanOrEqual(exp, Expression.Constant(Utils.GetDataReaderValue(exp.Type, fiValueRangeArray[0]), exp.Type)),
Expression.LessThan(exp, Expression.Constant(Utils.GetDataReaderValue(exp.Type, fiValueRangeArray[1]), exp.Type)));
break;
case DynamicFilterOperator.DateRange:
var fiValueDateRangeArray = getFiListValue();
if (fiValueDateRangeArray?.Length != 2) throw new ArgumentException($"DateRange 要求 Value 应该逗号分割,并且长度为 2");
if (fiValueDateRangeArray?.Length != 2) throw new ArgumentException(CoreStrings.DateRange_Comma_Separateda_By2Char);
if (Regex.IsMatch(fiValueDateRangeArray[1], @"^\d\d\d\d[\-/]\d\d?[\-/]\d\d?$")) fiValueDateRangeArray[1] = DateTime.Parse(fiValueDateRangeArray[1]).AddDays(1).ToString("yyyy-MM-dd HH:mm:ss");
else if (Regex.IsMatch(fiValueDateRangeArray[1], @"^\d\d\d\d[\-/]\d\d?$")) fiValueDateRangeArray[1] = DateTime.Parse($"{fiValueDateRangeArray[1]}-01").AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
else if (Regex.IsMatch(fiValueDateRangeArray[1], @"^\d\d\d\d$")) fiValueDateRangeArray[1] = DateTime.Parse($"{fiValueDateRangeArray[1]}-01-01").AddYears(1).ToString("yyyy-MM-dd HH:mm:ss");
else if (Regex.IsMatch(fiValueDateRangeArray[1], @"^\d\d\d\d[\-/]\d\d?[\-/]\d\d? \d\d?$")) fiValueDateRangeArray[1] = DateTime.Parse($"{fiValueDateRangeArray[1]}:00:00").AddHours(1).ToString("yyyy-MM-dd HH:mm:ss");
else if (Regex.IsMatch(fiValueDateRangeArray[1], @"^\d\d\d\d[\-/]\d\d?[\-/]\d\d? \d\d?:\d\d?$")) fiValueDateRangeArray[1] = DateTime.Parse($"{fiValueDateRangeArray[1]}:00").AddMinutes(1).ToString("yyyy-MM-dd HH:mm:ss");
else throw new ArgumentException($"DateRange 要求 Value[1] 格式必须为yyyy、yyyy-MM、yyyy-MM-dd、yyyy-MM-dd HH、yyyy、yyyy-MM-dd HH:mm");
else throw new ArgumentException(CoreStrings.DateRange_DateFormat_yyyy);
if (Regex.IsMatch(fiValueDateRangeArray[0], @"^\d\d\d\d[\-/]\d\d?$")) fiValueDateRangeArray[0] = DateTime.Parse($"{fiValueDateRangeArray[0]}-01").ToString("yyyy-MM-dd HH:mm:ss");
else if (Regex.IsMatch(fiValueDateRangeArray[0], @"^\d\d\d\d$")) fiValueDateRangeArray[0] = DateTime.Parse($"{fiValueDateRangeArray[0]}-01-01").ToString("yyyy-MM-dd HH:mm:ss");
@@ -774,7 +774,8 @@ namespace FreeSql.Internal.CommonProvider
}
catch { }
var dyattr = attrs?.Where(a => {
var dyattr = attrs?.Where(a =>
{
return ((a as Attribute)?.TypeId as Type)?.Name == "DynamicFilterCustomAttribute";
}).FirstOrDefault();
return dyattr != null;
@@ -800,7 +801,7 @@ namespace FreeSql.Internal.CommonProvider
public TSelect ForUpdate(bool noawait = false)
{
if (_transaction == null && _orm.Ado.TransactionCurrentThread == null)
throw new Exception("安全起见,请务必在事务开启之后,再使用 ForUpdate");
throw new Exception($"{CoreStrings.Begin_Transaction_Then_ForUpdate}");
switch (_orm.Ado.DataType)
{
case DataType.MySql:

View File

@@ -1,4 +1,4 @@
using FreeSql.Internal.Model;
using FreeSql.Internal.Model;
using System;
using System.Collections;
using System.Collections.Concurrent;
@@ -21,13 +21,13 @@ namespace FreeSql.Internal.CommonProvider
{
public DataTable ToDataTableByPropertyName(string[] properties)
{
if (properties?.Any() != true) throw new ArgumentException($"properties 参数不能为空");
if (properties?.Any() != true) throw new ArgumentException($"{CoreStrings.Properties_Cannot_Null}");
var sbfield = new StringBuilder();
for (var propIdx = 0; propIdx < properties.Length; propIdx++)
{
var property = properties[propIdx];
var exp = ConvertStringPropertyToExpression(property);
if (exp == null) throw new Exception($"{property} 属性名无法找到");
if (exp == null) throw new Exception(CoreStrings.Property_Cannot_Find(property));
var field = _commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null);
if (propIdx > 0) sbfield.Append(", ");
sbfield.Append(field);
@@ -225,7 +225,7 @@ namespace FreeSql.Internal.CommonProvider
}
public void ToChunk(int size, Action<FetchCallbackArgs<List<T1>>> done, bool includeNestedMembers = false)
{
if (_selectExpression != null) throw new ArgumentException("Chunk 功能之前不可使用 Select");
if (_selectExpression != null) throw new ArgumentException(CoreStrings.Before_Chunk_Cannot_Use_Select);
this.ToListChunkPrivate(size, done, includeNestedMembers == false ? this.GetAllFieldExpressionTreeLevel2() : this.GetAllFieldExpressionTreeLevelAll(), null);
}
@@ -776,7 +776,7 @@ namespace FreeSql.Internal.CommonProvider
protected TSelect InternalJoin<T2>(Expression exp, SelectTableInfoType joinType)
{
var tb = _commonUtils.GetTableByEntity(typeof(T2));
if (tb == null) throw new ArgumentException("T2 类型错误");
if (tb == null) throw new ArgumentException(CoreStrings.T2_Type_Error);
_tables.Add(new SelectTableInfo { Table = tb, Alias = $"IJ{_tables.Count}", On = null, Type = joinType });
_commonExpression.ExpressionJoinLambda(_tables, joinType, exp, null, _whereGlobalFilter);
return this as TSelect;
@@ -817,7 +817,7 @@ namespace FreeSql.Internal.CommonProvider
protected string InternalGetInsertIntoToSql<TTargetEntity>(string tableName, Expression select)
{
var tb = _orm.CodeFirst.GetTableByEntity(typeof(TTargetEntity));
if (tb == null) throw new ArgumentException($"ISelect.InsertInto() 类型错误: {typeof(TTargetEntity).DisplayCsharp()}");
if (tb == null) throw new ArgumentException(CoreStrings.InsertInto_TypeError(typeof(TTargetEntity).DisplayCsharp()));
if (string.IsNullOrEmpty(tableName)) tableName = tb.DbName;
if (_orm.CodeFirst.IsSyncStructureToLower) tableName = tableName.ToLower();
if (_orm.CodeFirst.IsSyncStructureToUpper) tableName = tableName.ToUpper();
@@ -829,8 +829,8 @@ namespace FreeSql.Internal.CommonProvider
_commonExpression.ReadAnonymousField(_tables, field, map, ref index, select, null, null, _whereGlobalFilter, null, false); //不走 DTO 映射,不处理 IncludeMany
var childs = map.Childs;
if (childs.Any() == false) throw new ArgumentException($"ISelect.InsertInto() 未选择属性: {typeof(TTargetEntity).DisplayCsharp()}");
foreach(var col in tb.Columns.Values)
if (childs.Any() == false) throw new ArgumentException(CoreStrings.InsertInto_No_Property_Selected(typeof(TTargetEntity).DisplayCsharp()));
foreach (var col in tb.Columns.Values)
{
if (col.Attribute.IsIdentity && string.IsNullOrEmpty(col.DbInsertValue)) continue;
if (col.Attribute.CanInsert == false) continue;
@@ -923,13 +923,13 @@ namespace FreeSql.Internal.CommonProvider
#else
public Task<DataTable> ToDataTableByPropertyNameAsync(string[] properties, CancellationToken cancellationToken)
{
if (properties?.Any() != true) throw new ArgumentException($"properties 参数不能为空");
if (properties?.Any() != true) throw new ArgumentException($"{CoreStrings.Properties_Cannot_Null}");
var sbfield = new StringBuilder();
for (var propIdx = 0; propIdx < properties.Length; propIdx++)
{
var property = properties[propIdx];
var exp = ConvertStringPropertyToExpression(property);
if (exp == null) throw new Exception($"{property} 属性名无法找到");
if (exp == null) throw new Exception(CoreStrings.Property_Cannot_Find(property));
var field = _commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null);
if (propIdx > 0) sbfield.Append(", ");
sbfield.Append(field);

View File

@@ -32,7 +32,7 @@ namespace FreeSql.Internal.CommonProvider
for (var a = 1; a < lambdaExp.Parameters.Count; a++)
{
var tb = _commonUtils.GetTableByEntity(lambdaExp.Parameters[a].Type);
if (tb == null) throw new ArgumentException($"{lambdaExp.Parameters[a].Name} 类型错误");
if (tb == null) throw new ArgumentException(CoreStrings.Type_Error_Name(lambdaExp.Parameters[a].Name));
_tables.Add(new SelectTableInfo { Table = tb, Alias = lambdaExp.Parameters[a].Name, On = null, Type = SelectTableInfoType.From });
}
}
@@ -81,8 +81,7 @@ namespace FreeSql.Internal.CommonProvider
case "LeftJoin": this.InternalJoin(expCall.Arguments[0], SelectTableInfoType.LeftJoin); break;
case "InnerJoin": this.InternalJoin(expCall.Arguments[0], SelectTableInfoType.InnerJoin); break;
case "RightJoin": this.InternalJoin(expCall.Arguments[0], SelectTableInfoType.RightJoin); break;
default: throw new NotImplementedException($"未实现 {expCall.Method.Name}");
default: throw new NotImplementedException(CoreStrings.Not_Implemented_Name(expCall.Method.Name));
}
}
}
@@ -118,7 +117,7 @@ namespace FreeSql.Internal.CommonProvider
public abstract ISelect<T1, T2, T3, T4, T5, T6, T7, T8> From<T2, T3, T4, T5, T6, T7, T8>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, ISelectFromExpression<T1>>> exp) where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class;
public abstract ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9> From<T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, ISelectFromExpression<T1>>> exp) where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class;
public abstract ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> From<T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, ISelectFromExpression<T1>>> exp) where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class;
public abstract ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> From<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, ISelectFromExpression<T1>>> exp) where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class;
public abstract ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> From<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, ISelectFromExpression<T1>>> exp) where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class;
public abstract ISelect<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> From<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(Expression<Func<ISelectFromExpression<T1>, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, ISelectFromExpression<T1>>> exp) where T2 : class where T3 : class where T4 : class where T5 : class where T6 : class where T7 : class where T8 : class where T9 : class where T10 : class where T11 : class where T12 : class where T13 : class;
@@ -244,7 +243,7 @@ namespace FreeSql.Internal.CommonProvider
var splitKeys = fim.Item1.Split('.');
var otherRetItem = otherRet[fim.Item3];
var otherRetItemType = _tables[0].Table.Type;
foreach(var splitKey in splitKeys)
foreach (var splitKey in splitKeys)
{
otherRetItem = _orm.GetEntityValueWithPropertyName(otherRetItemType, otherRetItem, splitKey);
otherRetItemType = _orm.CodeFirst.GetTableByEntity(otherRetItemType).Properties[splitKey].PropertyType;
@@ -263,7 +262,7 @@ namespace FreeSql.Internal.CommonProvider
.Where(a => a.Value.CsType != a.Value.Attribute.MapType)
.Select(a => new { DtoProperty = typeof(TDto).GetProperty(a.Value.CsName), EntityProperty = _tables[0].Table.Properties[a.Value.CsName], Column = a.Value })
.Where(a => a.DtoProperty != null)
.Select(a =>
.Select(a =>
a.DtoProperty.PropertyType == a.EntityProperty.PropertyType ?
Expression.Bind(a.DtoProperty, Expression.MakeMemberAccess(expParam, a.EntityProperty)) :
Expression.Bind(a.DtoProperty, Expression.Convert(Expression.MakeMemberAccess(expParam, a.EntityProperty), a.DtoProperty.PropertyType))
@@ -408,13 +407,13 @@ namespace FreeSql.Internal.CommonProvider
public ISelect<T1> IncludeByPropertyName(string property)
{
var exp = ConvertStringPropertyToExpression(property, true);
if (exp == null) throw new ArgumentException($"{nameof(property)} 无法解析为表达式树");
if (exp == null) throw new ArgumentException($"{CoreStrings.Cannot_Resolve_ExpressionTree(nameof(property))}");
var memExp = exp as MemberExpression;
if (memExp == null) throw new ArgumentException($"{nameof(property)} 无法解析为表达式树2");
if (memExp == null) throw new ArgumentException($"{CoreStrings.Cannot_Resolve_ExpressionTree(nameof(property))}2");
var parTb = _commonUtils.GetTableByEntity(memExp.Expression.Type);
if (parTb == null) throw new ArgumentException($"{nameof(property)} 无法解析为表达式树3");
if (parTb == null) throw new ArgumentException($"{CoreStrings.Cannot_Resolve_ExpressionTree(nameof(property))}3");
var parTbref = parTb.GetTableRef(memExp.Member.Name, true);
if (parTbref == null) throw new ArgumentException($"{nameof(property)} 不是有效的导航属性");
if (parTbref == null) throw new ArgumentException(CoreStrings.Not_Valid_Navigation_Property(nameof(property)));
switch (parTbref.RefType)
{
case TableRefType.ManyToMany:
@@ -422,7 +421,7 @@ namespace FreeSql.Internal.CommonProvider
var funcType = typeof(Func<,>).MakeGenericType(_tables[0].Table.Type, typeof(IEnumerable<>).MakeGenericType(parTbref.RefEntityType));
var navigateSelector = Expression.Lambda(funcType, exp, _tables[0].Parameter);
var incMethod = this.GetType().GetMethod("IncludeMany");
if (incMethod == null) throw new Exception("运行时错误,反射获取 IncludeMany 方法失败");
if (incMethod == null) throw new Exception(CoreStrings.RunTimeError_Reflection_IncludeMany);
incMethod.MakeGenericMethod(parTbref.RefEntityType).Invoke(this, new object[] { navigateSelector, null });
break;
case TableRefType.ManyToOne:
@@ -441,10 +440,10 @@ namespace FreeSql.Internal.CommonProvider
{
var expBody = navigateSelector?.Body;
if (expBody == null) return this;
if (expBody.NodeType != ExpressionType.MemberAccess) throw new Exception("Include 参数类型错误,表达式类型应该为 MemberAccess");
if (typeof(IEnumerable).IsAssignableFrom(expBody.Type)) throw new Exception("Include 参数类型错误,集合属性请使用 IncludeMany");
if (expBody.NodeType != ExpressionType.MemberAccess) throw new Exception(CoreStrings.Include_ParameterType_Error_Use_MemberAccess);
if (typeof(IEnumerable).IsAssignableFrom(expBody.Type)) throw new Exception(CoreStrings.Include_ParameterType_Error_Use_IncludeMany);
var tb = _commonUtils.GetTableByEntity(expBody.Type);
if (tb == null) throw new Exception("Include 参数类型错误");
if (tb == null) throw new Exception(CoreStrings.Include_ParameterType_Error);
_isIncluded = true;
_tables[0].Parameter = navigateSelector.Parameters[0];
@@ -472,18 +471,18 @@ namespace FreeSql.Internal.CommonProvider
isbreak = true;
break;
default:
throw new Exception($"表达式错误,它不是连续的 MemberAccess 类型:{exp}");
throw new Exception(CoreStrings.Expression_Error_Use_Successive_MemberAccess_Type(exp));
}
}
if (param == null) throw new Exception($"表达式错误,它的顶级对象不是 ParameterExpression{exp}");
if (param == null) throw new Exception(CoreStrings.Expression_Error_Use_ParameterExpression(exp));
return NativeTuple.Create(param, members.ToList());
}
static MethodInfo GetEntityValueWithPropertyNameMethod = typeof(EntityUtilExtensions).GetMethod("GetEntityValueWithPropertyName");
static ConcurrentDictionary<Type, ConcurrentDictionary<string, MethodInfo>> _dicTypeMethod = new ConcurrentDictionary<Type, ConcurrentDictionary<string, MethodInfo>>();
public ISelect<T1> IncludeMany<TNavigate>(Expression<Func<T1, IEnumerable<TNavigate>>> navigateSelector, Action<ISelect<TNavigate>> then = null) where TNavigate : class
{
var throwNavigateSelector = new Exception("IncludeMany 参数1 类型错误,表达式类型应该为 MemberAccess");
var throwNavigateSelector = new Exception(CoreStrings.IncludeMany_ParameterType_Error_Use_MemberAccess);
var expBody = navigateSelector?.Body;
if (expBody == null) return this;
if (expBody.NodeType == ExpressionType.Convert) expBody = (expBody as UnaryExpression)?.Operand; //- 兼容 Vb.Net 无法使用 IncludeMany 的问题;
@@ -492,7 +491,7 @@ namespace FreeSql.Internal.CommonProvider
Expression<Func<TNavigate, TNavigate>> selectExp = null;
while (expBody.NodeType == ExpressionType.Call)
{
throwNavigateSelector = new Exception($"IncludeMany {nameof(navigateSelector)} 参数类型错误,正确格式: a.collections.Take(1).Where(c => c.aid == a.id).Select(a => new TNavigate {{ }})");
throwNavigateSelector = new Exception(CoreStrings.IncludeMany_ParameterTypeError(nameof(navigateSelector)));
var callExp = (expBody as MethodCallExpression);
switch (callExp.Method.Name)
{
@@ -504,7 +503,7 @@ namespace FreeSql.Internal.CommonProvider
break;
case "Select":
selectExp = (callExp.Arguments[1] as Expression<Func<TNavigate, TNavigate>>);
if (selectExp?.Parameters.Count != 1) throw new Exception($"IncludeMany {nameof(navigateSelector)} 参数错误Select 只可以使用一个参数的方法,正确格式: .Select(t => new TNavigate {{ }})");
if (selectExp?.Parameters.Count != 1) throw new Exception(CoreStrings.IncludeMany_ParameterError_OnlyUseOneParameter(nameof(navigateSelector)));
break;
default: throw throwNavigateSelector;
}
@@ -519,10 +518,10 @@ namespace FreeSql.Internal.CommonProvider
var tb = _commonUtils.GetTableByEntity(collMem.Expression.Type);
if (tb == null) throw throwNavigateSelector;
var collMemElementType = (collMem.Type.IsGenericType ? collMem.Type.GetGenericArguments().FirstOrDefault() : collMem.Type.GetElementType());
if (typeof(TNavigate) != collMemElementType)
throw new Exception($"IncludeMany {nameof(navigateSelector)} 参数错误Select lambda参数返回值必须和 {collMemElementType} 类型一致");
if (typeof(TNavigate) != collMemElementType)
throw new Exception(CoreStrings.IncludeMany_ParameterError_Select_ReturnConsistentType(nameof(navigateSelector), collMemElementType));
var tbNav = _commonUtils.GetTableByEntity(typeof(TNavigate));
if (tbNav == null) throw new Exception($"类型 {typeof(TNavigate).FullName} 错误,不能使用 IncludeMany");
if (tbNav == null) throw new Exception(CoreStrings.TypeError_CannotUse_IncludeMany(typeof(TNavigate).FullName));
if (collMem.Expression.NodeType != ExpressionType.Parameter)
_commonExpression.ExpressionWhereLambda(_tables, Expression.MakeMemberAccess(collMem.Expression, tb.Properties[tb.ColumnsByCs.First().Value.CsName]), null, null, null);
@@ -532,7 +531,7 @@ namespace FreeSql.Internal.CommonProvider
if (whereExp == null)
{
tbref = tb.GetTableRef(collMem.Member.Name, true);
if (tbref == null) throw new Exception($"IncludeMany 类型 {tb.Type.DisplayCsharp()} 的属性 {collMem.Member.Name} 不是有效的导航属性提示IsIgnore = true 不会成为导航属性");
if (tbref == null) throw new Exception(CoreStrings.IncludeMany_NotValid_Navigation(tb.Type.DisplayCsharp(), collMem.Member.Name));
}
else
{
@@ -834,7 +833,7 @@ namespace FreeSql.Internal.CommonProvider
dicList.Clear();
};
if (tbref.RefType == TableRefType.OneToMany && _includeManySubListOneToManyTempValue1 != null && _includeManySubListOneToManyTempValue1 is List<TNavigate>)
if (tbref.RefType == TableRefType.OneToMany && _includeManySubListOneToManyTempValue1 != null && _includeManySubListOneToManyTempValue1 is List<TNavigate>)
{
fillOneToManyData(_includeManySubListOneToManyTempValue1 as List<TNavigate>, _commonUtils.GetTableByEntity(tbref.RefEntityType));
return;

View File

@@ -150,7 +150,7 @@ namespace FreeSql.Internal.CommonProvider
public string InternalToSql(string field)
{
if (string.IsNullOrEmpty(field))
throw new ArgumentException("参数 field 未指定");
throw new ArgumentException(CoreStrings.Parameter_Field_NotSpecified);
var isNestedPageSql = false;
switch (_orm.Ado.DataType)

View File

@@ -132,7 +132,7 @@ namespace FreeSql.Internal.CommonProvider
if (_table.VersionColumn != null && _source.Count > 0)
{
if (affrows != _source.Count)
throw new DbUpdateVersionException($"记录可能不存在,或者【行级乐观锁】版本过旧,更新数量{_source.Count},影响的行数{affrows}。", _table, sql, dbParms, affrows, _source.Select(a => (object)a));
throw new DbUpdateVersionException(CoreStrings.DbUpdateVersionException_RowLevelOptimisticLock(_source.Count, affrows), _table, sql, dbParms, affrows, _source.Select(a => (object)a));
foreach (var d in _source)
{
if (_table.VersionColumn.Attribute.MapType == typeof(byte[]))
@@ -224,7 +224,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
using (var conn = _orm.Ado.MasterPool.Get())
{
_transaction = conn.Value.BeginTransaction();
@@ -239,12 +239,12 @@ namespace FreeSql.Internal.CommonProvider
ret += this.RawExecuteAffrows();
}
_transaction.Commit();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "提交", null));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
}
catch (Exception ex)
{
_transaction.Rollback();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "回滚", ex));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
throw;
}
_transaction = null;
@@ -298,7 +298,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
using (var conn = _orm.Ado.MasterPool.Get())
{
_transaction = conn.Value.BeginTransaction();
@@ -313,12 +313,12 @@ namespace FreeSql.Internal.CommonProvider
ret.AddRange(this.RawExecuteUpdated());
}
_transaction.Commit();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "提交", null));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
}
catch (Exception ex)
{
_transaction.Rollback();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "回滚", ex));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
throw;
}
_transaction = null;
@@ -428,7 +428,7 @@ namespace FreeSql.Internal.CommonProvider
if (orm.Aop.AuditValueHandler == null) return;
if (data == null || table == null) return;
if (typeof(T1) == typeof(object) && new[] { table.Type, table.TypeLazy }.Contains(data.GetType()) == false)
throw new Exception($"操作的数据类型({data.GetType().DisplayCsharp()}) 与 AsType({table.Type.DisplayCsharp()}) 不一致,请检查。");
throw new Exception(CoreStrings.DataType_AsType_Inconsistent(data.GetType().DisplayCsharp(), table.Type.DisplayCsharp()));
foreach (var col in table.Columns.Values)
{
object val = col.GetValue(data);
@@ -558,9 +558,12 @@ namespace FreeSql.Internal.CommonProvider
if (initAssignExp == null) continue;
var memberName = initExp.Bindings[a].Member.Name;
if (_table.ColumnsByCsIgnore.ContainsKey(memberName)) continue;
if (_table.ColumnsByCs.TryGetValue(memberName, out var col) == false) throw new Exception($"找不到属性:{memberName}");
var memberValue = _commonExpression.ExpressionLambdaToSql(initAssignExp.Expression, new CommonExpression.ExpTSC { isQuoteName = true,
mapType = initAssignExp.Expression is BinaryExpression ? null : col.Attribute.MapType });
if (_table.ColumnsByCs.TryGetValue(memberName, out var col) == false) throw new Exception(CoreStrings.NotFound_Property(memberName));
var memberValue = _commonExpression.ExpressionLambdaToSql(initAssignExp.Expression, new CommonExpression.ExpTSC
{
isQuoteName = true,
mapType = initAssignExp.Expression is BinaryExpression ? null : col.Attribute.MapType
});
_setIncr.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ").Append(memberValue);
}
}
@@ -573,9 +576,12 @@ namespace FreeSql.Internal.CommonProvider
{
var memberName = newExp.Members[a].Name;
if (_table.ColumnsByCsIgnore.ContainsKey(memberName)) continue;
if (_table.ColumnsByCs.TryGetValue(memberName, out var col) == false) throw new Exception($"找不到属性:{memberName}");
var memberValue = _commonExpression.ExpressionLambdaToSql(newExp.Arguments[a], new CommonExpression.ExpTSC { isQuoteName = true,
mapType = newExp.Arguments[a] is BinaryExpression ? null : col.Attribute.MapType });
if (_table.ColumnsByCs.TryGetValue(memberName, out var col) == false) throw new Exception(CoreStrings.NotFound_Property(memberName));
var memberValue = _commonExpression.ExpressionLambdaToSql(newExp.Arguments[a], new CommonExpression.ExpTSC
{
isQuoteName = true,
mapType = newExp.Arguments[a] is BinaryExpression ? null : col.Attribute.MapType
});
_setIncr.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ").Append(memberValue);
}
}
@@ -672,7 +678,7 @@ namespace FreeSql.Internal.CommonProvider
protected string WhereCaseSource(string CsName, Func<string, string> thenValue)
{
if (_source.Any() == false) return null;
if (_table.ColumnsByCs.ContainsKey(CsName) == false) throw new Exception($"找不到 {CsName} 对应的列");
if (_table.ColumnsByCs.ContainsKey(CsName) == false) throw new Exception(CoreStrings.NotFound_CsName_Column(CsName));
if (thenValue == null) throw new ArgumentNullException(nameof(thenValue));
if (_source.Count == 0) return null;
@@ -757,10 +763,10 @@ namespace FreeSql.Internal.CommonProvider
}
public IUpdate<T1> AsType(Type entityType)
{
if (entityType == typeof(object)) throw new Exception("IUpdate.AsType 参数不支持指定为 object");
if (entityType == typeof(object)) throw new Exception(CoreStrings.TypeAsType_NotSupport_Object("IUpdate"));
if (entityType == _table.Type) return this;
var newtb = _commonUtils.GetTableByEntity(entityType);
_table = newtb ?? throw new Exception("IUpdate.AsType 参数错误,请传入正确的实体类型");
_table = newtb ?? throw new Exception(CoreStrings.Type_AsType_Parameter_Error("IUpdate"));
_tempPrimarys = _table.Primarys;
if (_orm.CodeFirst.IsAutoSyncStructure) _orm.CodeFirst.SyncStructure(entityType);
IgnoreCanUpdate();
@@ -1003,7 +1009,7 @@ namespace FreeSql.Internal.CommonProvider
sb.Append(" \r\nWHERE ");
if (_source.Any())
{
if (_tempPrimarys.Any() == false) throw new ArgumentException($"{_table.Type.DisplayCsharp()} 没有定义主键,无法使用 SetSource请尝试 SetDto");
if (_tempPrimarys.Any() == false) throw new ArgumentException(CoreStrings.NoPrimaryKey_UseSetDto(_table.Type.DisplayCsharp()));
sb.Append('(').Append(_commonUtils.WhereItems(_tempPrimarys, "", _source)).Append(')');
}

View File

@@ -51,7 +51,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
using (var conn = await _orm.Ado.MasterPool.GetAsync())
{
_transaction = conn.Value.BeginTransaction();
@@ -66,12 +66,12 @@ namespace FreeSql.Internal.CommonProvider
ret += await this.RawExecuteAffrowsAsync(cancellationToken);
}
_transaction.Commit();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "提交", null));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
}
catch (Exception ex)
{
_transaction.Rollback();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "回滚", ex));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
throw;
}
_transaction = null;
@@ -124,7 +124,7 @@ namespace FreeSql.Internal.CommonProvider
}
else
{
if (_orm.Ado.MasterPool == null) throw new Exception("Ado.MasterPool 值为 null该操作无法自启用事务请显式传递【事务对象】解决");
if (_orm.Ado.MasterPool == null) throw new Exception(CoreStrings.MasterPool_IsNull_UseTransaction);
using (var conn = await _orm.Ado.MasterPool.GetAsync())
{
_transaction = conn.Value.BeginTransaction();
@@ -139,12 +139,12 @@ namespace FreeSql.Internal.CommonProvider
ret.AddRange(await this.RawExecuteUpdatedAsync(cancellationToken));
}
_transaction.Commit();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "提交", null));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
}
catch (Exception ex)
{
_transaction.Rollback();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, "回滚", ex));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
throw;
}
_transaction = null;