#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

@ -42,7 +42,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
#region HasKey
public EfCoreTableFluent HasKey(string key)
{
if (key == null) throw new ArgumentException("参数错误 key 不能为 null");
if (key == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("key"));
foreach (string name in key.Split(','))
{
if (string.IsNullOrEmpty(name.Trim())) continue;
@ -55,7 +55,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
#region HasIndex
public HasIndexFluent HasIndex(string index)
{
if (index == null) throw new ArgumentException("参数错误 index 不能为 null");
if (index == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("index"));
var indexName = $"idx_{Guid.NewGuid().ToString("N").Substring(0, 8)}";
var columns = new List<string>();
foreach (string name in index.Split(','))
@ -98,8 +98,8 @@ namespace FreeSql.Extensions.EfCoreFluentApi
#region HasOne
public HasOneFluent HasOne(string one)
{
if (string.IsNullOrEmpty(one)) throw new ArgumentException("参数错误 one 不能为 null");
if (_entityType.GetPropertiesDictIgnoreCase().TryGetValue(one, out var oneProperty) == false) throw new ArgumentException($"参数错误 {one} 属性不存在");
if (string.IsNullOrEmpty(one)) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("one"));
if (_entityType.GetPropertiesDictIgnoreCase().TryGetValue(one, out var oneProperty) == false) throw new ArgumentException(DbContextStrings.ParameterError_NotFound_Property(one));
return new HasOneFluent(_fsql, _tf, _entityType, oneProperty.PropertyType, one);
}
public class HasOneFluent
@ -124,8 +124,8 @@ namespace FreeSql.Extensions.EfCoreFluentApi
}
public HasOneFluent WithMany(string many)
{
if (many == null) throw new ArgumentException("参数错误 many 不能为 null");
if (_entityType2.GetPropertiesDictIgnoreCase().TryGetValue(many, out var manyProperty) == false) throw new ArgumentException($"参数错误 {many} 属性不存在");
if (many == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("many"));
if (_entityType2.GetPropertiesDictIgnoreCase().TryGetValue(many, out var manyProperty) == false) throw new ArgumentException(DbContextStrings.ParameterError_NotFound_Property(many));
_withManyProperty = manyProperty.Name;
if (string.IsNullOrEmpty(_selfBind) == false)
_fsql.CodeFirst.ConfigEntity(_entityType2, eb2 => eb2.Navigate(many, _selfBind));
@ -133,18 +133,18 @@ namespace FreeSql.Extensions.EfCoreFluentApi
}
public HasOneFluent WithOne(string one, string foreignKey)
{
if (string.IsNullOrEmpty(one)) throw new ArgumentException("参数错误 one 不能为 null");
if (_entityType1.GetPropertiesDictIgnoreCase().TryGetValue(one, out var oneProperty) == false) throw new ArgumentException($"参数错误 {one} 属性不存在");
if (oneProperty != _entityType1) throw new ArgumentException($"参数错误 {one} 属性不存在");
if (string.IsNullOrEmpty(one)) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("one"));
if (_entityType1.GetPropertiesDictIgnoreCase().TryGetValue(one, out var oneProperty) == false) throw new ArgumentException(DbContextStrings.ParameterError_NotFound_Property(one));
if (oneProperty != _entityType1) throw new ArgumentException(DbContextStrings.ParameterError_NotFound_Property(one));
_withOneProperty = oneProperty.Name;
if (foreignKey == null) throw new ArgumentException("参数错误 foreignKey 不能为 null");
if (foreignKey == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("foreignKey"));
foreach (string name in foreignKey.Split(','))
{
if (string.IsNullOrEmpty(name.Trim())) continue;
_withOneBind += ", " + name.Trim();
}
if (string.IsNullOrEmpty(_withOneBind)) throw new ArgumentException("参数错误 foreignKey");
if (string.IsNullOrEmpty(_withOneBind)) throw new ArgumentException(DbContextStrings.ParameterError("foreignKey"));
_withOneBind = _withOneBind.TrimStart(',', ' ');
if (string.IsNullOrEmpty(_selfBind) == false)
_fsql.CodeFirst.ConfigEntity(_entityType2, eb2 => eb2.Navigate(_withOneProperty, _withOneBind));
@ -152,13 +152,13 @@ namespace FreeSql.Extensions.EfCoreFluentApi
}
public HasOneFluent HasForeignKey(string foreignKey)
{
if (foreignKey == null) throw new ArgumentException("参数错误 foreignKey 不能为 null");
if (foreignKey == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("foreignKey"));
foreach (string name in foreignKey.Split(','))
{
if (string.IsNullOrEmpty(name.Trim())) continue;
_selfBind += ", " + name.Trim();
}
if (string.IsNullOrEmpty(_selfBind)) throw new ArgumentException("参数错误 foreignKey");
if (string.IsNullOrEmpty(_selfBind)) throw new ArgumentException(DbContextStrings.ParameterError("foreignKey"));
_selfBind = _selfBind.TrimStart(',', ' ');
_tf.Navigate(_selfProperty, _selfBind);
if (string.IsNullOrEmpty(_withManyProperty) == false)
@ -173,9 +173,9 @@ namespace FreeSql.Extensions.EfCoreFluentApi
#region HasMany
public HasManyFluent HasMany(string many)
{
if (string.IsNullOrEmpty(many)) throw new ArgumentException("参数错误 many 不能为 null");
if (_entityType.GetPropertiesDictIgnoreCase().TryGetValue(many, out var manyProperty) == false) throw new ArgumentException($"参数错误 {many} 集合属性不存在");
if (typeof(IEnumerable).IsAssignableFrom(manyProperty.PropertyType) == false || manyProperty.PropertyType.IsGenericType == false) throw new ArgumentException("参数错误 {many} 不是集合属性");
if (string.IsNullOrEmpty(many)) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("many"));
if (_entityType.GetPropertiesDictIgnoreCase().TryGetValue(many, out var manyProperty) == false) throw new ArgumentException(DbContextStrings.ParameterError_NotFound_CollectionProperties(many));
if (typeof(IEnumerable).IsAssignableFrom(manyProperty.PropertyType) == false || manyProperty.PropertyType.IsGenericType == false) throw new ArgumentException(DbContextStrings.ParameterError_IsNot_CollectionProperties(many));
return new HasManyFluent(_fsql, _tf, _entityType, manyProperty.PropertyType.GetGenericArguments()[0], manyProperty.Name);
}
public class HasManyFluent
@ -200,18 +200,18 @@ namespace FreeSql.Extensions.EfCoreFluentApi
public void WithMany(string many, Type middleType)
{
if (string.IsNullOrEmpty(many)) throw new ArgumentException("参数错误 many 不能为 null");
if (_entityType2.GetPropertiesDictIgnoreCase().TryGetValue(many, out var manyProperty) == false) throw new ArgumentException($"参数错误 {many} 集合属性不存在");
if (typeof(IEnumerable).IsAssignableFrom(manyProperty.PropertyType) == false || manyProperty.PropertyType.IsGenericType == false) throw new ArgumentException("参数错误 {many} 不是集合属性");
if (string.IsNullOrEmpty(many)) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("many"));
if (_entityType2.GetPropertiesDictIgnoreCase().TryGetValue(many, out var manyProperty) == false) throw new ArgumentException(DbContextStrings.ParameterError_NotFound_CollectionProperties(many));
if (typeof(IEnumerable).IsAssignableFrom(manyProperty.PropertyType) == false || manyProperty.PropertyType.IsGenericType == false) throw new ArgumentException(DbContextStrings.ParameterError_IsNot_CollectionProperties(many));
_withManyProperty = manyProperty.Name;
_tf.Navigate(_selfProperty, null, middleType);
_fsql.CodeFirst.ConfigEntity(_entityType2, eb2 => eb2.Navigate(_withManyProperty, null, middleType));
}
public HasManyFluent WithOne(string one)
{
if (string.IsNullOrEmpty(one)) throw new ArgumentException("参数错误 one 不能为 null");
if (_entityType2.GetPropertiesDictIgnoreCase().TryGetValue(one, out var oneProperty) == false) throw new ArgumentException($"参数错误 {one} 属性不存在");
if (oneProperty.PropertyType != _entityType1) throw new ArgumentException($"参数错误 {one} 属性不存在");
if (string.IsNullOrEmpty(one)) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("one"));
if (_entityType2.GetPropertiesDictIgnoreCase().TryGetValue(one, out var oneProperty) == false) throw new ArgumentException(DbContextStrings.ParameterError_NotFound_Property(one));
if (oneProperty.PropertyType != _entityType1) throw new ArgumentException(DbContextStrings.ParameterError_NotFound_Property(one));
_withOneProperty = oneProperty.Name;
if (string.IsNullOrEmpty(_selfBind) == false)
_fsql.CodeFirst.ConfigEntity(_entityType2, eb2 => eb2.Navigate(oneProperty.Name, _selfBind));
@ -219,13 +219,13 @@ namespace FreeSql.Extensions.EfCoreFluentApi
}
public HasManyFluent HasForeignKey(string foreignKey)
{
if (foreignKey == null) throw new ArgumentException("参数错误 foreignKey 不能为 null");
if (foreignKey == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("foreignKey"));
foreach (string name in foreignKey.Split(','))
{
if (string.IsNullOrEmpty(name.Trim())) continue;
_selfBind += ", " + name.Trim();
}
if (string.IsNullOrEmpty(_selfBind)) throw new ArgumentException("参数错误 foreignKey");
if (string.IsNullOrEmpty(_selfBind)) throw new ArgumentException(DbContextStrings.ParameterError("foreignKey"));
_selfBind = _selfBind.TrimStart(',', ' ');
_tf.Navigate(_selfProperty, _selfBind);
if (string.IsNullOrEmpty(_withOneProperty) == false)

View File

@ -42,7 +42,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
{
var exp = key?.Body;
if (exp?.NodeType == ExpressionType.Convert) exp = (exp as UnaryExpression)?.Operand;
if (exp == null) throw new ArgumentException("参数错误 key 不能为 null");
if (exp == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("key"));
switch (exp.NodeType)
{
@ -63,7 +63,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
{
var exp = index?.Body;
if (exp?.NodeType == ExpressionType.Convert) exp = (exp as UnaryExpression)?.Operand;
if (exp == null) throw new ArgumentException("参数错误 index 不能为 null");
if (exp == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("index"));
var indexName = $"idx_{Guid.NewGuid().ToString("N").Substring(0, 8)}";
var columns = new List<string>();
@ -114,7 +114,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
{
var exp = one?.Body;
if (exp?.NodeType == ExpressionType.Convert) exp = (exp as UnaryExpression)?.Operand;
if (exp == null) throw new ArgumentException("参数错误 one 不能为 null");
if (exp == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("one"));
var oneProperty = "";
switch (exp.NodeType)
@ -123,7 +123,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
oneProperty = (exp as MemberExpression).Member.Name;
break;
}
if (string.IsNullOrEmpty(oneProperty)) throw new ArgumentException("参数错误 one");
if (string.IsNullOrEmpty(oneProperty)) throw new ArgumentException(DbContextStrings.ParameterError("one"));
return new HasOneFluent<T2>(_fsql, _tf, oneProperty);
}
public class HasOneFluent<T2>
@ -146,7 +146,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
{
var exp = many?.Body;
if (exp?.NodeType == ExpressionType.Convert) exp = (exp as UnaryExpression)?.Operand;
if (exp == null) throw new ArgumentException("参数错误 many 不能为 null");
if (exp == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("many"));
switch (exp.NodeType)
{
@ -154,7 +154,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
_withManyProperty = (exp as MemberExpression).Member.Name;
break;
}
if (string.IsNullOrEmpty(_withManyProperty)) throw new ArgumentException("参数错误 many");
if (string.IsNullOrEmpty(_withManyProperty)) throw new ArgumentException(DbContextStrings.ParameterError("many"));
if (string.IsNullOrEmpty(_selfBind) == false)
_fsql.CodeFirst.ConfigEntity<T2>(eb2 => eb2.Navigate(_withManyProperty, _selfBind));
return this;
@ -163,7 +163,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
{
var exp = one?.Body;
if (exp?.NodeType == ExpressionType.Convert) exp = (exp as UnaryExpression)?.Operand;
if (exp == null) throw new ArgumentException("参数错误 one 不能为 null");
if (exp == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("one"));
switch (exp.NodeType)
{
@ -171,11 +171,11 @@ namespace FreeSql.Extensions.EfCoreFluentApi
_withOneProperty = (exp as MemberExpression).Member.Name;
break;
}
if (string.IsNullOrEmpty(_withOneProperty)) throw new ArgumentException("参数错误 one");
if (string.IsNullOrEmpty(_withOneProperty)) throw new ArgumentException(DbContextStrings.ParameterError("one"));
exp = foreignKey?.Body;
if (exp?.NodeType == ExpressionType.Convert) exp = (exp as UnaryExpression)?.Operand;
if (exp == null) throw new ArgumentException("参数错误 foreignKey 不能为 null");
if (exp == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("foreignKey"));
switch (exp.NodeType)
{
@ -190,7 +190,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
_withOneBind = _withOneBind.TrimStart(',', ' ');
break;
}
if (string.IsNullOrEmpty(_withOneBind)) throw new ArgumentException("参数错误 foreignKey");
if (string.IsNullOrEmpty(_withOneBind)) throw new ArgumentException(DbContextStrings.ParameterError("foreignKey"));
if (string.IsNullOrEmpty(_selfBind) == false)
_fsql.CodeFirst.ConfigEntity<T2>(eb2 => eb2.Navigate(_withOneProperty, _withOneBind));
return this;
@ -199,7 +199,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
{
var exp = foreignKey?.Body;
if (exp?.NodeType == ExpressionType.Convert) exp = (exp as UnaryExpression)?.Operand;
if (exp == null) throw new ArgumentException("参数错误 foreignKey 不能为 null");
if (exp == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("foreignKey"));
switch (exp.NodeType)
{
@ -214,7 +214,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
_selfBind = _selfBind.TrimStart(',', ' ');
break;
}
if (string.IsNullOrEmpty(_selfBind)) throw new ArgumentException("参数错误 foreignKey");
if (string.IsNullOrEmpty(_selfBind)) throw new ArgumentException(DbContextStrings.ParameterError("foreignKey"));
_tf.Navigate(_selfProperty, _selfBind);
if (string.IsNullOrEmpty(_withManyProperty) == false)
_fsql.CodeFirst.ConfigEntity<T2>(eb2 => eb2.Navigate(_withManyProperty, _selfBind));
@ -230,7 +230,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
{
var exp = many?.Body;
if (exp?.NodeType == ExpressionType.Convert) exp = (exp as UnaryExpression)?.Operand;
if (exp == null) throw new ArgumentException("参数错误 many 不能为 null");
if (exp == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("many"));
var manyProperty = "";
switch (exp.NodeType)
@ -239,7 +239,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
manyProperty = (exp as MemberExpression).Member.Name;
break;
}
if (string.IsNullOrEmpty(manyProperty)) throw new ArgumentException("参数错误 many");
if (string.IsNullOrEmpty(manyProperty)) throw new ArgumentException(DbContextStrings.ParameterError("many"));
return new HasManyFluent<T2>(_fsql, _tf, manyProperty);
}
public class HasManyFluent<T2>
@ -262,7 +262,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
{
var exp = many?.Body;
if (exp?.NodeType == ExpressionType.Convert) exp = (exp as UnaryExpression)?.Operand;
if (exp == null) throw new ArgumentException("参数错误 many 不能为 null");
if (exp == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("many"));
switch (exp.NodeType)
{
@ -270,7 +270,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
_withManyProperty = (exp as MemberExpression).Member.Name;
break;
}
if (string.IsNullOrEmpty(_withManyProperty)) throw new ArgumentException("参数错误 many");
if (string.IsNullOrEmpty(_withManyProperty)) throw new ArgumentException(DbContextStrings.ParameterError("many"));
_tf.Navigate(_selfProperty, null, middleType);
_fsql.CodeFirst.ConfigEntity<T2>(eb2 => eb2.Navigate(_withManyProperty, null, middleType));
@ -279,7 +279,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
{
var exp = one?.Body;
if (exp?.NodeType == ExpressionType.Convert) exp = (exp as UnaryExpression)?.Operand;
if (exp == null) throw new ArgumentException("参数错误 one 不能为 null");
if (exp == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("one"));
switch (exp.NodeType)
{
@ -287,7 +287,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
_withOneProperty = (exp as MemberExpression).Member.Name;
break;
}
if (string.IsNullOrEmpty(_withOneProperty)) throw new ArgumentException("参数错误 one");
if (string.IsNullOrEmpty(_withOneProperty)) throw new ArgumentException(DbContextStrings.ParameterError("one"));
if (string.IsNullOrEmpty(_selfBind) == false)
_fsql.CodeFirst.ConfigEntity<T2>(eb2 => eb2.Navigate(_withOneProperty, _selfBind));
@ -297,7 +297,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
{
var exp = foreignKey?.Body;
if (exp?.NodeType == ExpressionType.Convert) exp = (exp as UnaryExpression)?.Operand;
if (exp == null) throw new ArgumentException("参数错误 foreignKey 不能为 null");
if (exp == null) throw new ArgumentException(DbContextStrings.ParameterError_CannotBeNull("foreignKey"));
switch (exp.NodeType)
{
@ -312,7 +312,7 @@ namespace FreeSql.Extensions.EfCoreFluentApi
_selfBind = _selfBind.TrimStart(',', ' ');
break;
}
if (string.IsNullOrEmpty(_selfBind)) throw new ArgumentException("参数错误 foreignKey");
if (string.IsNullOrEmpty(_selfBind)) throw new ArgumentException(DbContextStrings.ParameterError("foreignKey"));
_tf.Navigate(_selfProperty, _selfBind);
if (string.IsNullOrEmpty(_withOneProperty) == false)
_fsql.CodeFirst.ConfigEntity<T2>(eb2 => eb2.Navigate(_withOneProperty, _selfBind));