mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
#694 ✨ Exception信息 国际化 多语言
This commit is contained in:
@ -135,7 +135,8 @@ namespace FreeSql.Internal
|
||||
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||
parent.Childs.Add(child);
|
||||
}
|
||||
if (_tables.Count > 1) { //如果下级导航属性被 Include 过,则将他们也查询出来
|
||||
if (_tables.Count > 1)
|
||||
{ //如果下级导航属性被 Include 过,则将他们也查询出来
|
||||
foreach (var memProp in tb.Properties.Values)
|
||||
{
|
||||
var memtbref = tb.GetTableRef(memProp.Name, false);
|
||||
@ -162,8 +163,8 @@ namespace FreeSql.Internal
|
||||
}
|
||||
else
|
||||
{
|
||||
if (select != null && findIncludeMany != null && select._includeToList.Any() && exp.Type.IsGenericType &&
|
||||
typeof(IEnumerable).IsAssignableFrom(exp.Type) &&
|
||||
if (select != null && findIncludeMany != null && select._includeToList.Any() && exp.Type.IsGenericType &&
|
||||
typeof(IEnumerable).IsAssignableFrom(exp.Type) &&
|
||||
typeof(ICollection<>).MakeGenericType(exp.Type.GetGenericArguments().FirstOrDefault()).IsAssignableFrom(exp.Type))
|
||||
{
|
||||
var includeKey = "";
|
||||
@ -285,7 +286,7 @@ namespace FreeSql.Internal
|
||||
ReadAnonymousField(_tables, field, child, ref index, initAssignExp.Expression, select, diymemexp, whereGlobalFilter, findIncludeMany, false);
|
||||
}
|
||||
}
|
||||
if (parent.Childs.Any() == false) throw new Exception($"映射异常:{initExp.NewExpression.Type.Name} 没有一个属性名相同");
|
||||
if (parent.Childs.Any() == false) throw new Exception(CoreStrings.Mapping_Exception_HasNo_SamePropertyName(initExp.NewExpression.Type.Name));
|
||||
return true;
|
||||
case ExpressionType.New:
|
||||
var newExp = exp as NewExpression;
|
||||
@ -350,7 +351,7 @@ namespace FreeSql.Internal
|
||||
}
|
||||
}
|
||||
}
|
||||
if (parent.Childs.Any() == false) throw new Exception($"映射异常:{newExp.Type.Name} 没有一个属性名相同");
|
||||
if (parent.Childs.Any() == false) throw new Exception(CoreStrings.Mapping_Exception_HasNo_SamePropertyName(newExp.Type.Name));
|
||||
return true;
|
||||
}
|
||||
parent.DbField = $"({ExpressionLambdaToSql(exp, getTSC())})";
|
||||
@ -367,13 +368,13 @@ namespace FreeSql.Internal
|
||||
if (notRead)
|
||||
{
|
||||
++index;
|
||||
if (parent.Property != null)
|
||||
if (parent.Property != null)
|
||||
return Utils.GetDataReaderValue(parent.Property.PropertyType, null);
|
||||
return Utils.GetDataReaderValue(parent.CsType, null);
|
||||
}
|
||||
object objval = Utils.InternalDataReaderGetValue(_common, dr, ++index); // dr.GetValue(++index);
|
||||
if (dbValue != null) dbValue.DbValue = objval == DBNull.Value ? null : objval;
|
||||
if (parent.CsType != parent.MapType)
|
||||
if (parent.CsType != parent.MapType)
|
||||
objval = Utils.GetDataReaderValue(parent.MapType, objval);
|
||||
objval = Utils.GetDataReaderValue(parent.CsType, objval);
|
||||
if (parent.Property != null && parent.CsType != parent.Property.PropertyType)
|
||||
@ -468,7 +469,7 @@ namespace FreeSql.Internal
|
||||
var newArrMembers = new List<string>();
|
||||
foreach (var newArrExp in newArr.Expressions) newArrMembers.AddRange(ExpressionSelectColumns_MemberAccess_New_NewArrayInit(_tables, newArrExp, isQuoteName, diymemexp));
|
||||
return newArrMembers.Distinct().Select(a => a.Trim('\'')).ToArray();
|
||||
default: throw new ArgumentException($"无法解析表达式:{exp}");
|
||||
default: throw new ArgumentException(CoreStrings.Unable_Parse_Expression(exp));
|
||||
}
|
||||
return new string[0];
|
||||
}
|
||||
@ -623,9 +624,9 @@ namespace FreeSql.Internal
|
||||
ColumnInfo rightMapColumn = null;
|
||||
var isRightMapType = false;
|
||||
if (isLeftMapType) oldMapType = tsc.SetMapTypeReturnOld(leftMapColumn.Attribute.MapType);
|
||||
|
||||
|
||||
var right = ExpressionLambdaToSql(rightExp, tsc);
|
||||
if (right != "NULL" && isLeftMapType &&
|
||||
if (right != "NULL" && isLeftMapType &&
|
||||
//判断参数化后的bug
|
||||
!(right.Contains('@') || right.Contains('?') || right.Contains(':')) &&
|
||||
//三元表达式后,取消此条件 #184
|
||||
@ -787,12 +788,13 @@ namespace FreeSql.Internal
|
||||
exp3.Method.GetCustomAttributes(typeof(ExpressionCallAttribute), true).Any()
|
||||
))
|
||||
{
|
||||
var ecc = new ExpressionCallContext {
|
||||
_commonExp = this,
|
||||
_tsc = tsc,
|
||||
DataType = _ado.DataType,
|
||||
UserParameters = tsc.dbParams == null ? null : new List<DbParameter>(),
|
||||
FormatSql = obj => formatSql(obj, null, null, null)
|
||||
var ecc = new ExpressionCallContext
|
||||
{
|
||||
_commonExp = this,
|
||||
_tsc = tsc,
|
||||
DataType = _ado.DataType,
|
||||
UserParameters = tsc.dbParams == null ? null : new List<DbParameter>(),
|
||||
FormatSql = obj => formatSql(obj, null, null, null)
|
||||
};
|
||||
var exp3MethodParams = exp3.Method.GetParameters();
|
||||
var dbParamsIndex = tsc.dbParams?.Count;
|
||||
@ -852,10 +854,10 @@ namespace FreeSql.Internal
|
||||
else
|
||||
exp3InvokeParams[a] = ecc;
|
||||
}
|
||||
var eccFields = _dicTypeExpressionCallClassContextFields.GetOrAdd(exp3.Method.DeclaringType, dttp =>
|
||||
var eccFields = _dicTypeExpressionCallClassContextFields.GetOrAdd(exp3.Method.DeclaringType, dttp =>
|
||||
dttp.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Static).Where(a => a.FieldType == typeof(ThreadLocal<ExpressionCallContext>)).ToArray());
|
||||
if (eccFields.Any() == false)
|
||||
throw new Exception($"自定义表达式解析错误:类型 {exp3.Method.DeclaringType} 需要定义 static ThreadLocal<ExpressionCallContext> 字段、字段、字段(重要三次提醒)");
|
||||
throw new Exception(CoreStrings.Custom_Expression_ParsingError(exp3.Method.DeclaringType));
|
||||
foreach (var eccField in eccFields)
|
||||
typeof(ThreadLocal<ExpressionCallContext>).GetProperty("Value").SetValue(eccField.GetValue(null), ecc, null);
|
||||
try
|
||||
@ -999,7 +1001,7 @@ namespace FreeSql.Internal
|
||||
fsql = Expression.Lambda(exp3tmpTestCall).Compile().DynamicInvoke();
|
||||
var fsqlFindMethod = fsql.GetType().GetMethod(exp3tmpCall.Method.Name, exp3tmpCall.Arguments.Select(a => a.Type).ToArray());
|
||||
if (fsqlFindMethod == null)
|
||||
throw new Exception($"无法解析表达式方法 {exp3tmpCall.Method.Name}");
|
||||
throw new Exception(CoreStrings.Unable_Parse_ExpressionMethod(exp3tmpCall.Method.Name));
|
||||
var exp3StackOld = exp3Stack;
|
||||
exp3Stack = new Stack<Expression>();
|
||||
exp3Stack.Push(Expression.Call(Expression.Constant(fsql), fsqlFindMethod, exp3tmpCall.Arguments));
|
||||
@ -1010,7 +1012,8 @@ namespace FreeSql.Internal
|
||||
fsqlType = fsql?.GetType();
|
||||
if (fsqlType == null) break;
|
||||
var fsqlSelect0 = fsql as Select0Provider;
|
||||
switch (exp3.Method.Name) {
|
||||
switch (exp3.Method.Name)
|
||||
{
|
||||
case "Any": //exists
|
||||
switch (_ado.DataType)
|
||||
{
|
||||
@ -1035,7 +1038,7 @@ namespace FreeSql.Internal
|
||||
//fsqltables[0].Alias = $"{tsc._tables[0].Alias}_{fsqltables[0].Alias}";
|
||||
if (fsqltables != tsc._tables)
|
||||
{
|
||||
if (tsc._tables == null && tsc.diymemexp == null) throw new NotSupportedException($"这个特别的子查询不能解析"); //2020-12-11 IUpdate 条件不支持子查询
|
||||
if (tsc._tables == null && tsc.diymemexp == null) throw new NotSupportedException(CoreStrings.EspeciallySubquery_Cannot_Parsing); //2020-12-11 IUpdate 条件不支持子查询
|
||||
if (tsc._tables != null) //groupby is null
|
||||
{
|
||||
fsqltables.AddRange(tsc._tables.Select(a => new SelectTableInfo
|
||||
@ -1230,7 +1233,7 @@ namespace FreeSql.Internal
|
||||
var exp3Args0 = (exp3.Arguments[0] as UnaryExpression)?.Operand as LambdaExpression;
|
||||
manySubSelectAggMethod = _dicSelectMethodToSql.GetOrAdd(fsqlType, fsqlType2 =>
|
||||
fsqlType2.GetMethods().Where(a => a.Name == "ToSql" && a.GetParameters().Length == 2 && a.GetParameters()[1].ParameterType == typeof(FieldAliasOptions) && a.GetGenericArguments().Length == 1).FirstOrDefault());
|
||||
if (manySubSelectAggMethod == null || exp3Args0 == null) throw new ArgumentException($"ManyToMany 导航属性 .AsSelect() 暂时不可用于 Sum/Avg/Max/Min/First/ToOne/ToList 方法");
|
||||
if (manySubSelectAggMethod == null || exp3Args0 == null) throw new ArgumentException(CoreStrings.ManyToMany_AsSelect_NotSupport_Sum_Avg_etc);
|
||||
manySubSelectAggMethod = manySubSelectAggMethod.MakeGenericMethod(exp3Args0.ReturnType);
|
||||
var fsqls0p = fsql as Select0Provider;
|
||||
var fsqls0pWhere = fsqls0p._where.ToString();
|
||||
@ -1358,8 +1361,8 @@ namespace FreeSql.Internal
|
||||
other3Exp = ExpressionLambdaToSqlOther(exp3, tsc);
|
||||
if (string.IsNullOrEmpty(other3Exp) == false) return other3Exp;
|
||||
if (exp3.IsParameter() == false) return formatSql(Expression.Lambda(exp3).Compile().DynamicInvoke(), tsc.mapType, tsc.mapColumnTmp, tsc.dbParams);
|
||||
if (exp3.Method.DeclaringType == typeof(Enumerable)) throw new Exception($"未实现函数表达式 {exp3} 解析。如果正在操作导航属性集合,请使用 .AsSelect().{exp3.Method.Name}({(exp3.Arguments.Count > 1 ? "..." : "")})");
|
||||
throw new Exception($"未实现函数表达式 {exp3} 解析");
|
||||
if (exp3.Method.DeclaringType == typeof(Enumerable)) throw new Exception(CoreStrings.Not_Implemented_Expression_UseAsSelect(exp3, exp3.Method.Name, (exp3.Arguments.Count > 1 ? "..." : "")));
|
||||
throw new Exception(CoreStrings.Not_Implemented_Expression(exp3));
|
||||
case ExpressionType.Parameter:
|
||||
case ExpressionType.MemberAccess:
|
||||
var exp4 = exp as MemberExpression;
|
||||
@ -1434,7 +1437,7 @@ namespace FreeSql.Internal
|
||||
break;
|
||||
case ExpressionType.MemberAccess:
|
||||
var expStackFirstMem = expStack.First() as MemberExpression;
|
||||
if (expStackFirstMem.Expression?.NodeType == ExpressionType.Constant)
|
||||
if (expStackFirstMem.Expression?.NodeType == ExpressionType.Constant)
|
||||
firstValue = (expStackFirstMem.Expression as ConstantExpression)?.Value;
|
||||
else
|
||||
return formatSql(Expression.Lambda(exp).Compile().DynamicInvoke(), tsc.mapType, tsc.mapColumnTmp, tsc.dbParams);
|
||||
@ -1479,8 +1482,8 @@ namespace FreeSql.Internal
|
||||
if (tb.ColumnsByCs.ContainsKey(memberExp.Member.Name) == false)
|
||||
{
|
||||
if (tb.ColumnsByCsIgnore.ContainsKey(memberExp.Member.Name))
|
||||
throw new ArgumentException($"{tb.DbName}.{memberExp.Member.Name} 被忽略,请检查 IsIgnore 设置,确认 get/set 为 public");
|
||||
throw new ArgumentException($"{tb.DbName} 找不到列 {memberExp.Member.Name}");
|
||||
throw new ArgumentException(CoreStrings.Ignored_Check_Confirm_PublicGetSet(tb.DbName, memberExp.Member.Name));
|
||||
throw new ArgumentException(CoreStrings.NotFound_Column(tb.DbName, memberExp.Member.Name));
|
||||
}
|
||||
var curcol = tb.ColumnsByCs[memberExp.Member.Name];
|
||||
if (tsc._selectColumnMap != null)
|
||||
@ -1497,7 +1500,7 @@ namespace FreeSql.Internal
|
||||
if (tsc.style == ExpressionStyle.SelectColumns)
|
||||
{
|
||||
finds = tsc._tables.Where(a => a.Table.Type == tbtmp.Type && a.Alias == alias).ToArray();
|
||||
if (finds.Any() == false && alias.Contains("__") == false)
|
||||
if (finds.Any() == false && alias.Contains("__") == false)
|
||||
finds = tsc._tables.Where(a => a.Table.Type == tbtmp.Type).ToArray();
|
||||
if (finds.Any()) finds = new[] { finds.First() };
|
||||
}
|
||||
@ -1595,7 +1598,7 @@ namespace FreeSql.Internal
|
||||
switch (exp2.NodeType)
|
||||
{
|
||||
case ExpressionType.Constant:
|
||||
throw new NotImplementedException("未实现 MemberAccess 下的 Constant");
|
||||
throw new NotImplementedException($"{CoreStrings.Not_Implemented_MemberAcess_Constant}");
|
||||
case ExpressionType.Parameter:
|
||||
case ExpressionType.MemberAccess:
|
||||
|
||||
@ -1666,10 +1669,10 @@ namespace FreeSql.Internal
|
||||
}
|
||||
}
|
||||
if (tb2.ColumnsByCsIgnore.ContainsKey(mp2.Member.Name))
|
||||
throw new ArgumentException($"{tb2.DbName}.{mp2.Member.Name} 被忽略,请检查 IsIgnore 设置,确认 get/set 为 public");
|
||||
throw new ArgumentException(CoreStrings.Ignored_Check_Confirm_PublicGetSet(tb2.DbName, mp2.Member.Name));
|
||||
if (tb2.GetTableRef(mp2.Member.Name, false) != null)
|
||||
throw new ArgumentException($"{tb2.DbName}.{mp2.Member.Name} 导航属性集合忘了 .AsSelect() 吗?如果在 ToList(a => a.{mp2.Member.Name}) 中使用,请移步参考 IncludeMany 文档。");
|
||||
throw new ArgumentException($"{tb2.DbName} 找不到列 {mp2.Member.Name}");
|
||||
throw new ArgumentException(CoreStrings.Navigation_Missing_AsSelect(tb2.DbName, mp2.Member.Name));
|
||||
throw new ArgumentException(CoreStrings.NotFound_Column(tb2.DbName, mp2.Member.Name));
|
||||
}
|
||||
col2 = tb2.ColumnsByCs[mp2.Member.Name];
|
||||
if (tsc._selectColumnMap != null && find2 != null)
|
||||
@ -1834,9 +1837,19 @@ namespace FreeSql.Internal
|
||||
new ReplaceParameterVisitor().Modify(fl.Where, newParameter),
|
||||
newParameter
|
||||
);
|
||||
var whereSql = ExpressionLambdaToSql(expExp.Body, new ExpTSC { _tables =
|
||||
isMultitb ? new List<SelectTableInfo>(new[] { tb }) : null,
|
||||
_selectColumnMap = null, diymemexp = null, tbtype = SelectTableInfoType.From, isQuoteName = true, isDisableDiyParse = false, style = ExpressionStyle.Where, currentTable = tb.Table, alias001 = tb.Alias });
|
||||
var whereSql = ExpressionLambdaToSql(expExp.Body, new ExpTSC
|
||||
{
|
||||
_tables =
|
||||
isMultitb ? new List<SelectTableInfo>(new[] { tb }) : null,
|
||||
_selectColumnMap = null,
|
||||
diymemexp = null,
|
||||
tbtype = SelectTableInfoType.From,
|
||||
isQuoteName = true,
|
||||
isDisableDiyParse = false,
|
||||
style = ExpressionStyle.Where,
|
||||
currentTable = tb.Table,
|
||||
alias001 = tb.Alias
|
||||
});
|
||||
whereSql = GetBoolString(expExp.Body, whereSql);
|
||||
if (isEmpty == false)
|
||||
sb.Append(" AND ");
|
||||
@ -2121,7 +2134,7 @@ namespace FreeSql.Internal
|
||||
e.Result = $"({select.ToSql().Replace(" \r\n", " \r\n ")})";
|
||||
return;
|
||||
}
|
||||
throw throwCallExp(" 不支持");
|
||||
throw throwCallExp(CoreStrings.Not_Support);
|
||||
case "ToList":
|
||||
if (callExp.Arguments.Count == 1)
|
||||
{
|
||||
@ -2130,7 +2143,7 @@ namespace FreeSql.Internal
|
||||
e.Result = $"({select.ToSql().Replace(" \r\n", " \r\n ")})";
|
||||
return;
|
||||
}
|
||||
throw throwCallExp(" 不支持");
|
||||
throw throwCallExp(CoreStrings.Not_Support);
|
||||
case "Contains":
|
||||
if (callExp.Arguments.Count == 2)
|
||||
{
|
||||
@ -2148,7 +2161,7 @@ namespace FreeSql.Internal
|
||||
select.Distinct();
|
||||
break;
|
||||
}
|
||||
throw throwCallExp(" 不支持");
|
||||
throw throwCallExp(CoreStrings.Not_Support);
|
||||
case "OrderBy":
|
||||
select._tables[0].Parameter = (callExp.Arguments[1] as LambdaExpression)?.Parameters.FirstOrDefault();
|
||||
LocalSetSelectProviderAlias(select._tables[0].Parameter.Name);
|
||||
@ -2179,7 +2192,7 @@ namespace FreeSql.Internal
|
||||
select.InternalWhere(whereParam);
|
||||
break;
|
||||
}
|
||||
throw throwCallExp(" 不支持");
|
||||
throw throwCallExp(CoreStrings.Not_Support);
|
||||
|
||||
case "Skip":
|
||||
select.Offset((int)callExp.Arguments[1].GetConstExprValue());
|
||||
@ -2197,9 +2210,9 @@ namespace FreeSql.Internal
|
||||
select._selectExpression = selectParam;
|
||||
break;
|
||||
}
|
||||
throw throwCallExp(" 不支持");
|
||||
throw throwCallExp(CoreStrings.Not_Support);
|
||||
}
|
||||
Exception throwCallExp(string message) => new Exception($"解析失败 {callExp.Method.Name} {message}");
|
||||
Exception throwCallExp(string message) => new Exception(CoreStrings.Parsing_Failed(callExp.Method.Name,message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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(')');
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -123,12 +123,12 @@ namespace FreeSql.Internal.ObjectPool
|
||||
{
|
||||
|
||||
var conn = GetFree(false);
|
||||
if (conn == null) throw new Exception($"CheckAvailable: Failed to get resource {this.Statistics}");
|
||||
|
||||
if (conn == null) throw new Exception(CoreStrings.Available_Failed_Get_Resource("CheckAvailable", this.Statistics));
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
if (Policy.OnCheckAvailable(conn) == false) throw new Exception("CheckAvailable: An exception needs to be thrown");
|
||||
if (Policy.OnCheckAvailable(conn) == false) throw new Exception(CoreStrings.Available_Thrown_Exception("CheckAvailable"));
|
||||
break;
|
||||
|
||||
}
|
||||
@ -187,22 +187,22 @@ namespace FreeSql.Internal.ObjectPool
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
var conn = GetFree(false);
|
||||
if (conn == null) throw new Exception($"LiveCheckAvailable: Failed to get resource {this.Statistics}");
|
||||
|
||||
if (conn == null) throw new Exception(CoreStrings.Available_Failed_Get_Resource("LiveCheckAvailable", this.Statistics));
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
if (Policy.OnCheckAvailable(conn) == false) throw new Exception("LiveCheckAvailable: An exception needs to be thrown");
|
||||
|
||||
|
||||
if (Policy.OnCheckAvailable(conn) == false) throw new Exception(CoreStrings.Available_Thrown_Exception("LiveCheckAvailable"));
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
|
||||
Return(conn);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -275,11 +275,10 @@ namespace FreeSql.Internal.ObjectPool
|
||||
{
|
||||
|
||||
if (running == false)
|
||||
throw new ObjectDisposedException($"【{Policy.Name}】The ObjectPool has been disposed, see: https://github.com/dotnetcore/FreeSql/discussions/1079");
|
||||
throw new ObjectDisposedException(CoreStrings.Policy_ObjectPool_Dispose(Policy.Name));
|
||||
|
||||
if (checkAvailable && UnavailableException != null)
|
||||
throw new Exception($"【{Policy.Name}】Block access and wait for recovery: {UnavailableException?.Message}, see: https://github.com/dotnetcore/FreeSql/discussions/1080", UnavailableException);
|
||||
//throw new Exception($"【{Policy.Name}】状态不可用,等待后台检查程序恢复方可使用。{UnavailableException?.Message}");
|
||||
throw new Exception(CoreStrings.Policy_Status_NotAvailable(Policy.Name,UnavailableException?.Message), UnavailableException);
|
||||
|
||||
if ((_freeObjects.TryPop(out var obj) == false || obj == null) && _allObjects.Count < Policy.PoolSize)
|
||||
{
|
||||
@ -341,7 +340,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
Policy.OnGetTimeout();
|
||||
|
||||
if (Policy.IsThrowGetTimeoutException)
|
||||
throw new TimeoutException($"【{Policy.Name}】ObjectPool.Get() timeout {timeout.Value.TotalSeconds} seconds, see: https://github.com/dotnetcore/FreeSql/discussions/1081");
|
||||
throw new TimeoutException(CoreStrings.ObjectPool_Get_Timeout(Policy.Name, "Get", timeout.Value.TotalSeconds));
|
||||
|
||||
return null;
|
||||
}
|
||||
@ -375,7 +374,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
{
|
||||
|
||||
if (Policy.AsyncGetCapacity > 0 && _getAsyncQueue.Count >= Policy.AsyncGetCapacity - 1)
|
||||
throw new OutOfMemoryException($"【{Policy.Name}】ObjectPool.GetAsync() The queue is too long. Policy.AsyncGetCapacity = {Policy.AsyncGetCapacity}");
|
||||
throw new OutOfMemoryException(CoreStrings.ObjectPool_GetAsync_Queue_Long(Policy.Name, Policy.AsyncGetCapacity));
|
||||
|
||||
var tcs = new TaskCompletionSource<Object<T>>();
|
||||
|
||||
|
@ -87,7 +87,7 @@ namespace FreeSql.Internal
|
||||
else colattr.IsIgnore = true;
|
||||
//Navigate 错误提示
|
||||
var pnvAttr = common.GetEntityNavigateAttribute(trytb.Type, p);
|
||||
if (pnvAttr != null) throw new Exception($"【导航属性】{trytb.Type.DisplayCsharp()}.{p.Name} 缺少 set 属性");
|
||||
if (pnvAttr != null) throw new Exception(CoreStrings.Navigation_Missing_SetProperty(trytb.Type.DisplayCsharp(),p.Name));
|
||||
}
|
||||
if (tp == null && colattr?.IsIgnore != true)
|
||||
{
|
||||
@ -381,8 +381,8 @@ namespace FreeSql.Internal
|
||||
colattr.DbType = Regex.Replace(colattr.DbType, decimalPatten, $"$1({colattr.Precision},{colattr.Scale})");
|
||||
}
|
||||
|
||||
if (trytb.Columns.ContainsKey(colattr.Name)) throw new Exception($"ColumnAttribute.Name {colattr.Name} 重复存在,请检查(注意:不区分大小写)");
|
||||
if (trytb.ColumnsByCs.ContainsKey(p.Name)) throw new Exception($"属性名 {p.Name} 重复存在,请检查(注意:不区分大小写)");
|
||||
if (trytb.Columns.ContainsKey(colattr.Name)) throw new Exception(CoreStrings.Duplicate_ColumnAttribute(colattr.Name));
|
||||
if (trytb.ColumnsByCs.ContainsKey(p.Name)) throw new Exception(CoreStrings.Duplicate_PropertyName(p.Name));
|
||||
|
||||
trytb.Columns.Add(colattr.Name, col);
|
||||
trytb.ColumnsByCs.Add(p.Name, col);
|
||||
@ -392,7 +392,7 @@ namespace FreeSql.Internal
|
||||
if (trytb.VersionColumn != null)
|
||||
{
|
||||
if (trytb.VersionColumn.Attribute.MapType.IsNullableType() || trytb.VersionColumn.Attribute.MapType.IsNumberType() == false && trytb.VersionColumn.Attribute.MapType != typeof(byte[]))
|
||||
throw new Exception($"属性{trytb.VersionColumn.CsName} 被标注为行锁(乐观锁)(IsVersion),但其必须为数字类型 或者 byte[],并且不可为 Nullable");
|
||||
throw new Exception(CoreStrings.Properties_AsRowLock_Must_Numeric_Byte(trytb.VersionColumn.CsName));
|
||||
}
|
||||
tbattr?.ParseAsTable(trytb);
|
||||
|
||||
@ -550,7 +550,7 @@ namespace FreeSql.Internal
|
||||
StringBuilder cscode = null;
|
||||
if (common.CodeFirst.IsLazyLoading && propsLazy.Any())
|
||||
{
|
||||
if (trytb.Type.IsPublic == false && trytb.Type.IsNestedPublic == false) throw new Exception($"【延时加载】实体类型 {trytbTypeName} 必须声明为 public");
|
||||
if (trytb.Type.IsPublic == false && trytb.Type.IsNestedPublic == false) throw new Exception(CoreStrings.LazyLoading_EntityMustDeclarePublic(trytbTypeName));
|
||||
|
||||
trytbTypeLazyName = $"FreeSqlLazyEntity__{Regex.Replace(trytbTypeName, @"[^\w\d]", "_")}";
|
||||
|
||||
@ -576,14 +576,14 @@ namespace FreeSql.Internal
|
||||
{
|
||||
cscode.AppendLine("}");
|
||||
Assembly assembly = null;
|
||||
if (MethodLazyLoadingComplier.Value == null) throw new Exception("【延时加载】功能需要安装 FreeSql.Extensions.LazyLoading.dll,可前往 nuget 下载");
|
||||
if (MethodLazyLoadingComplier.Value == null) throw new Exception(CoreStrings.Install_FreeSql_Extensions_LazyLoading);
|
||||
try
|
||||
{
|
||||
assembly = MethodLazyLoadingComplier.Value.Invoke(null, new object[] { cscode.ToString() }) as Assembly;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"【延时加载】{trytbTypeName} 编译错误:{ex.Message}\r\n\r\n{cscode}");
|
||||
throw new Exception(CoreStrings.LazyLoading_CompilationError(trytbTypeName, ex.Message, cscode)); ;
|
||||
}
|
||||
var type = assembly.GetExportedTypes()/*.DefinedTypes*/.Where(a => a.FullName.EndsWith(trytbTypeLazyName)).FirstOrDefault();
|
||||
trytb.TypeLazy = type;
|
||||
@ -618,7 +618,7 @@ namespace FreeSql.Internal
|
||||
if (typeof(IEnumerable).IsAssignableFrom(pnv.PropertyType) == false) return;
|
||||
if (trytb.Primarys.Any() == false)
|
||||
{
|
||||
nvref.Exception = new Exception($"导航属性 {trytbTypeName}.{pnv.Name} 解析错误,实体类型 {trytbTypeName} 缺少主键标识,[Column(IsPrimary = true)]");
|
||||
nvref.Exception = new Exception(CoreStrings.Navigation_ParsingError_EntityMissingPrimaryKey(trytbTypeName, pnv.Name, trytbTypeName));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
return;
|
||||
@ -651,7 +651,7 @@ namespace FreeSql.Internal
|
||||
|
||||
if (isManyToMany == false)
|
||||
{
|
||||
nvref.Exception = new Exception($"【ManyToMany】导航属性 {trytbTypeName}.{pnv.Name} 解析错误,实体类型 {tbrefTypeName} 必须存在对应的 [Navigate(ManyToMany = x)] 集合属性");
|
||||
nvref.Exception = new Exception(CoreStrings.ManyToMany_ParsingError_EntityMustHas_NavigateCollection(trytbTypeName, pnv.Name, tbrefTypeName));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
return;
|
||||
@ -674,7 +674,7 @@ namespace FreeSql.Internal
|
||||
{
|
||||
if (tbref.Primarys.Any() == false)
|
||||
{
|
||||
nvref.Exception = new Exception($"【ManyToMany】导航属性 {trytbTypeName}.{pnv.Name} 解析错误,实体类型 {tbrefTypeName} 缺少主键标识,[Column(IsPrimary = true)]");
|
||||
nvref.Exception = new Exception(CoreStrings.ManyToMany_ParsingError_EntityMissing_PrimaryKey(trytbTypeName, pnv.Name, tbrefTypeName));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
return;
|
||||
@ -773,7 +773,7 @@ namespace FreeSql.Internal
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
nvref.Exception = new Exception($"【ManyToMany】导航属性 {trytbTypeName}.{pnv.Name} 解析错误,中间类 {tbmid.CsName}.{midTypePropsTrytb.Name} 错误:{ex.Message}");
|
||||
nvref.Exception = new Exception(CoreStrings.ManyToMany_ParsingError_IntermediateClass_ErrorMessage(trytbTypeName, pnv.Name, tbmid.CsName, midTypePropsTrytb.Name, ex.Message));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
}
|
||||
@ -781,7 +781,7 @@ namespace FreeSql.Internal
|
||||
{
|
||||
if (trytbTf.RefType != TableRefType.ManyToOne && trytbTf.RefType != TableRefType.OneToOne)
|
||||
{
|
||||
nvref.Exception = new Exception($"【ManyToMany】导航属性 {trytbTypeName}.{pnv.Name} 解析错误,中间类 {tbmid.CsName}.{midTypePropsTrytb.Name} 导航属性不是【ManyToOne】或【OneToOne】");
|
||||
nvref.Exception = new Exception(CoreStrings.ManyToMany_ParsingError_IntermediateClass_NotManyToOne_OneToOne(trytbTypeName, pnv.Name, tbmid.CsName, midTypePropsTrytb.Name));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
}
|
||||
@ -820,7 +820,7 @@ namespace FreeSql.Internal
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
nvref.Exception = new Exception($"【ManyToMany】导航属性 {tbrefTypeName}.{pnv.Name} 解析错误,中间类 {tbmid.CsName}.{midTypePropsTbref.Name} 错误:{ex.Message}");
|
||||
nvref.Exception = new Exception(CoreStrings.ManyToMany_ParsingError_IntermediateClass_ErrorMessage(trytbTypeName, pnv.Name, tbmid.CsName, midTypePropsTbref.Name, ex.Message));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
}
|
||||
@ -828,7 +828,7 @@ namespace FreeSql.Internal
|
||||
{
|
||||
if (tbrefTf.RefType != TableRefType.ManyToOne && tbrefTf.RefType != TableRefType.OneToOne)
|
||||
{
|
||||
nvref.Exception = new Exception($"【ManyToMany】导航属性 {tbrefTypeName}.{pnv.Name} 解析错误,中间类 {tbmid.CsName}.{midTypePropsTbref.Name} 导航属性不是【ManyToOne】或【OneToOne】");
|
||||
nvref.Exception = new Exception(CoreStrings.ManyToMany_ParsingError_IntermediateClass_NotManyToOne_OneToOne(trytbTypeName, pnv.Name, tbmid.CsName, midTypePropsTbref.Name));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
}
|
||||
@ -866,14 +866,14 @@ namespace FreeSql.Internal
|
||||
}
|
||||
if (trycol != null && trycol.CsType.NullableTypeOrThis() != trytb.Primarys[a].CsType.NullableTypeOrThis())
|
||||
{
|
||||
nvref.Exception = new Exception($"【ManyToMany】导航属性 {trytbTypeName}.{pnv.Name} 解析错误,{tbmid.CsName}.{trycol.CsName} 和 {trytb.CsName}.{trytb.Primarys[a].CsName} 类型不一致");
|
||||
nvref.Exception = new Exception(CoreStrings.ManyToMany_ParsingError_InconsistentType(trytbTypeName, pnv.Name, tbmid.CsName, trycol.CsName, trytb.CsName, trytb.Primarys[a].CsName));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
break;
|
||||
}
|
||||
if (trycol == null)
|
||||
{
|
||||
nvref.Exception = new Exception($"【ManyToMany】导航属性 {trytbTypeName}.{pnv.Name} 在 {tbmid.CsName} 中没有找到对应的字段,如:{midTypePropsTrytb.Name}{findtrytbPkCsName}、{midTypePropsTrytb.Name}_{findtrytbPkCsName}");
|
||||
nvref.Exception = new Exception(CoreStrings.ManyToMany_NotFound_CorrespondingField(trytbTypeName, pnv.Name, tbmid.CsName, midTypePropsTrytb.Name, findtrytbPkCsName));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
break;
|
||||
@ -906,14 +906,14 @@ namespace FreeSql.Internal
|
||||
}
|
||||
if (trycol != null && trycol.CsType.NullableTypeOrThis() != tbref.Primarys[a].CsType.NullableTypeOrThis())
|
||||
{
|
||||
nvref.Exception = new Exception($"【ManyToMany】导航属性 {trytbTypeName}.{pnv.Name} 解析错误,{tbmid.CsName}.{trycol.CsName} 和 {tbref.CsName}.{tbref.Primarys[a].CsName} 类型不一致");
|
||||
nvref.Exception = new Exception(CoreStrings.ManyToMany_ParsingError_InconsistentType(trytbTypeName, pnv.Name, tbmid.CsName, trycol.CsName, trytb.CsName, trytb.Primarys[a].CsName));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
break;
|
||||
}
|
||||
if (trycol == null)
|
||||
{
|
||||
nvref.Exception = new Exception($"【ManyToMany】导航属性 {trytbTypeName}.{pnv.Name} 在 {tbmid.CsName} 中没有找到对应的字段,如:{midTypePropsTbref.Name}{findtbrefPkCsName}、{midTypePropsTbref.Name}_{findtbrefPkCsName}");
|
||||
nvref.Exception = new Exception(CoreStrings.ManyToMany_NotFound_CorrespondingField(trytbTypeName, pnv.Name, tbmid.CsName, midTypePropsTrytb.Name, findtbrefPkCsName));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
break;
|
||||
@ -987,7 +987,7 @@ namespace FreeSql.Internal
|
||||
{
|
||||
if (tbref.ColumnsByCs.TryGetValue(bi, out var trybindcol) == false)
|
||||
{
|
||||
nvref.Exception = new Exception($"导航属性 {trytbTypeName}.{pnv.Name} 特性 [Navigate] 解析错误,在 {tbrefTypeName} 未找到属性:{bi}");
|
||||
nvref.Exception = new Exception(CoreStrings.Navigation_ParsingError_NotFound_Property(trytbTypeName, pnv.Name, tbrefTypeName, bi));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
break;
|
||||
@ -1003,7 +1003,7 @@ namespace FreeSql.Internal
|
||||
|
||||
if (nvref.Exception == null && bindColumns.Any() && bindColumns.Count != trytb.Primarys.Length)
|
||||
{
|
||||
nvref.Exception = new Exception($"导航属性 {trytbTypeName}.{pnv.Name} 特性 [Navigate] Bind 数目({bindColumns.Count}) 与 内部主键数目({trytb.Primarys.Length}) 不相同");
|
||||
nvref.Exception = new Exception(CoreStrings.Navigation_Bind_Number_Different(trytbTypeName, pnv.Name, bindColumns.Count, trytb.Primarys.Length));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
}
|
||||
@ -1043,14 +1043,15 @@ namespace FreeSql.Internal
|
||||
}
|
||||
if (trycol != null && trycol.CsType.NullableTypeOrThis() != trytb.Primarys[a].CsType.NullableTypeOrThis())
|
||||
{
|
||||
nvref.Exception = new Exception($"【OneToMany】导航属性 {trytbTypeName}.{pnv.Name} 解析错误,{trytb.CsName}.{trytb.Primarys[a].CsName} 和 {tbref.CsName}.{trycol.CsName} 类型不一致");
|
||||
nvref.Exception = new Exception(CoreStrings.OneToMany_ParsingError_InconsistentType(trytbTypeName, pnv.Name, trytb.CsName, trytb.Primarys[a].CsName, tbref.CsName, trycol.CsName));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
break;
|
||||
}
|
||||
if (trycol == null)
|
||||
{
|
||||
nvref.Exception = new Exception($"【OneToMany】导航属性 {trytbTypeName}.{pnv.Name} 在 {tbref.CsName} 中没有找到对应的字段,如:{findtrytb}{findtrytbPkCsName}、{findtrytb}_{findtrytbPkCsName}" + (refprop == null ? "" : $"、{refprop.Name}{findtrytbPkCsName}、{refprop.Name}_{findtrytbPkCsName}。或者使用 [Navigate] 特性指定关系映射。"));
|
||||
nvref.Exception = new Exception(CoreStrings.OneToMany_NotFound_CorrespondingField(trytbTypeName, pnv.Name, tbref.CsName, findtrytb, findtrytbPkCsName)
|
||||
+ (refprop == null ? "" : CoreStrings.OneToMany_UseNavigate(refprop.Name, findtrytbPkCsName)));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
break;
|
||||
@ -1127,7 +1128,7 @@ namespace FreeSql.Internal
|
||||
if (tbref == null) return;
|
||||
if (tbref.Primarys.Any() == false)
|
||||
{
|
||||
nvref.Exception = new Exception($"导航属性 {trytbTypeName}.{pnv.Name} 解析错误,实体类型 {propTypeName} 缺少主键标识,[Column(IsPrimary = true)]");
|
||||
nvref.Exception = new Exception(CoreStrings.Navigation_ParsingError_EntityMissingPrimaryKey(trytbTypeName, pnv.Name, propTypeName));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
}
|
||||
@ -1144,7 +1145,7 @@ namespace FreeSql.Internal
|
||||
{
|
||||
if (trytb.ColumnsByCs.TryGetValue(bi, out var trybindcol) == false)
|
||||
{
|
||||
nvref.Exception = new Exception($"导航属性 {trytbTypeName}.{pnv.Name} 特性 [Navigate] 解析错误,在 {trytbTypeName} 未找到属性:{bi}");
|
||||
nvref.Exception = new Exception(CoreStrings.Navigation_ParsingError_NotFound_Property(trytbTypeName, pnv.Name, trytbTypeName, bi));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
break;
|
||||
@ -1156,7 +1157,7 @@ namespace FreeSql.Internal
|
||||
|
||||
if (nvref.Exception == null && bindColumns.Any() && bindColumns.Count != tbref.Primarys.Length)
|
||||
{
|
||||
nvref.Exception = new Exception($"导航属性 {trytbTypeName}.{pnv.Name} 特性 [Navigate] Bind 数目({bindColumns.Count}) 与 外部主键数目({tbref.Primarys.Length}) 不相同");
|
||||
nvref.Exception = new Exception(CoreStrings.Navigation_Bind_Number_Different(trytbTypeName, pnv.Name, bindColumns.Count, tbref.Primarys.Length));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
}
|
||||
@ -1211,14 +1212,14 @@ namespace FreeSql.Internal
|
||||
}
|
||||
if (trycol != null && trycol.CsType.NullableTypeOrThis() != tbref.Primarys[a].CsType.NullableTypeOrThis())
|
||||
{
|
||||
nvref.Exception = new Exception($"导航属性 {trytbTypeName}.{pnv.Name} 解析错误,{trytb.CsName}.{trycol.CsName} 和 {tbref.CsName}.{tbref.Primarys[a].CsName} 类型不一致");
|
||||
nvref.Exception = new Exception(CoreStrings.Navigation_ParsingError_InconsistentType(trytbTypeName, pnv.Name, trytb.CsName, trycol.CsName, tbref.CsName, tbref.Primarys[a].CsName));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
break;
|
||||
}
|
||||
if (trycol == null)
|
||||
{
|
||||
nvref.Exception = new Exception($"导航属性 {trytbTypeName}.{pnv.Name} 没有找到对应的字段,如:{pnv.Name}{findtbrefPkCsName}、{pnv.Name}_{findtbrefPkCsName}。或者使用 [Navigate] 特性指定关系映射。");
|
||||
nvref.Exception = new Exception(CoreStrings.Navigation_NotFound_CorrespondingField(trytbTypeName, pnv.Name, findtbrefPkCsName));
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
break;
|
||||
@ -1793,7 +1794,7 @@ namespace FreeSql.Internal
|
||||
var parmValue = Expression.Parameter(typeof(object), "value");
|
||||
Expression exp = Expression.Convert(parmInfo, typeObj);
|
||||
foreach (var pro in memberAccessPath.Split('.'))
|
||||
exp = Expression.PropertyOrField(exp, pro) ?? throw new Exception(string.Concat(exp.Type.FullName, " 没有定义属性 ", pro));
|
||||
exp = Expression.PropertyOrField(exp, pro) ?? throw new Exception(string.Concat(exp.Type.FullName, CoreStrings.NoProperty_Defined, pro));
|
||||
|
||||
var value2 = Expression.Call(MethodGetDataReaderValue, Expression.Constant(exp.Type), parmValue);
|
||||
var value3 = Expression.Convert(parmValue, typeValue);
|
||||
@ -2261,7 +2262,7 @@ namespace FreeSql.Internal
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ArgumentException($"ExpressionTree 转换类型错误,值({string.Concat(value)}),类型({value.GetType().FullName}),目标类型({type.FullName}),{ex.Message}");
|
||||
throw new ArgumentException(CoreStrings.ExpressionTree_Convert_Type_Error(string.Concat(value), value.GetType().FullName, type.FullName, ex.Message));
|
||||
}
|
||||
}
|
||||
public static string GetCsName(string name)
|
||||
@ -2359,7 +2360,7 @@ namespace FreeSql.Internal
|
||||
var ltidx = ltidxStack.Pop();
|
||||
var ltidx2 = ltidx;
|
||||
var sidx2 = sidx;
|
||||
while(sidx < locsql.Length)
|
||||
while (sidx < locsql.Length)
|
||||
{
|
||||
var chr2 = locsql[sidx];
|
||||
if (chr2 == ')')
|
||||
|
Reference in New Issue
Block a user