mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-03-16 02:50:57 +08:00
- 修复 MySql JsonMap Enum 统一解析为 int;#2040
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using FreeSql;
|
||||
using FreeSql.DataAnnotations;
|
||||
using FreeSql.Internal.CommonProvider;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
@@ -121,10 +122,97 @@ public static class FreeSqlJsonMapCoreExtensions
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//解析 POCO Json a.Customer.Name
|
||||
if (e.Expression is MemberExpression memExp)
|
||||
//处理 mysql enum -> int
|
||||
switch (fsql.Ado.DataType)
|
||||
{
|
||||
if (e.Expression.IsParameter() == false) return;
|
||||
case DataType.MySql:
|
||||
case DataType.OdbcMySql:
|
||||
case DataType.CustomMySql:
|
||||
if (e.Expression.NodeType == ExpressionType.Equal &&
|
||||
e.Expression is BinaryExpression binaryExpression)
|
||||
{
|
||||
var comonExp = (fsql.Select<object>() as Select0Provider)._commonExpression;
|
||||
var leftExp = binaryExpression.Left;
|
||||
var rightExp = binaryExpression.Right;
|
||||
if (
|
||||
leftExp.NodeType == ExpressionType.Convert &&
|
||||
leftExp is UnaryExpression leftExpUexp &&
|
||||
leftExpUexp.Operand?.Type.NullableTypeOrThis().IsEnum == true &&
|
||||
|
||||
rightExp.NodeType == ExpressionType.Convert &&
|
||||
rightExp is UnaryExpression rightExpUexp &&
|
||||
rightExpUexp.Operand?.Type.NullableTypeOrThis().IsEnum == true)
|
||||
{
|
||||
string leftSql = null, rightSql = null;
|
||||
if (leftExpUexp.Operand.NodeType == ExpressionType.MemberAccess &&
|
||||
LocalParseMemberExp(leftExpUexp.Operand as MemberExpression))
|
||||
leftSql = e.Result;
|
||||
|
||||
if (rightExpUexp.Operand.NodeType == ExpressionType.MemberAccess &&
|
||||
LocalParseMemberExp(rightExpUexp.Operand as MemberExpression))
|
||||
rightSql = e.Result;
|
||||
|
||||
if (!string.IsNullOrEmpty(leftSql) && string.IsNullOrEmpty(rightSql) && !rightExpUexp.Operand.IsParameter())
|
||||
rightSql = comonExp.formatSql(Expression.Lambda(rightExpUexp.Operand).Compile().DynamicInvoke(), typeof(int), null, null);
|
||||
if (string.IsNullOrEmpty(leftSql) && !string.IsNullOrEmpty(rightSql) && !leftExpUexp.Operand.IsParameter())
|
||||
leftSql = comonExp.formatSql(Expression.Lambda(leftExpUexp.Operand).Compile().DynamicInvoke(), typeof(int), null, null);
|
||||
|
||||
if (!string.IsNullOrEmpty(leftSql) && !string.IsNullOrEmpty(rightSql))
|
||||
{
|
||||
e.Result = $"{leftSql} = {rightSql}";
|
||||
return;
|
||||
}
|
||||
e.Result = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (e.Expression.NodeType == ExpressionType.Call &&
|
||||
e.Expression is MethodCallExpression callExp &&
|
||||
callExp.Method.Name == "Contains")
|
||||
{
|
||||
var objExp = callExp.Object;
|
||||
var objType = objExp?.Type;
|
||||
if (objType?.FullName == "System.Byte[]") return;
|
||||
|
||||
var argIndex = 0;
|
||||
if (objType == null && callExp.Method.DeclaringType == typeof(Enumerable))
|
||||
{
|
||||
objExp = callExp.Arguments.FirstOrDefault();
|
||||
objType = objExp?.Type;
|
||||
argIndex++;
|
||||
|
||||
if (objType == typeof(string)) return;
|
||||
}
|
||||
if (objType == null) objType = callExp.Method.DeclaringType;
|
||||
if (objType != null || objType.IsArrayOrList())
|
||||
{
|
||||
var memExp = callExp.Arguments[argIndex];
|
||||
if (memExp.NodeType == ExpressionType.MemberAccess &&
|
||||
memExp.Type.NullableTypeOrThis().IsEnum &&
|
||||
LocalParseMemberExp(memExp as MemberExpression))
|
||||
{
|
||||
if (!objExp.IsParameter())
|
||||
{
|
||||
var comonExp = (fsql.Select<object>() as Select0Provider)._commonExpression;
|
||||
var rightSql = comonExp.formatSql(Expression.Lambda(objExp).Compile().DynamicInvoke(), typeof(int), null, null);
|
||||
e.Result = $"{e.Result} in {rightSql.Replace(", \r\n \r\n", $") \r\n OR {e.Result} in (")}";
|
||||
return;
|
||||
}
|
||||
e.Result = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
//解析 POCO Json a.Customer.Name
|
||||
if (e.Expression.NodeType == ExpressionType.MemberAccess)
|
||||
LocalParseMemberExp(e.Expression as MemberExpression);
|
||||
|
||||
bool LocalParseMemberExp(MemberExpression memExp)
|
||||
{
|
||||
if (memExp == null) return false;
|
||||
if (e.Expression.IsParameter() == false) return false;
|
||||
var parentMemExps = new Stack<MemberExpression>();
|
||||
parentMemExps.Push(memExp);
|
||||
while (true)
|
||||
@@ -133,25 +221,25 @@ public static class FreeSqlJsonMapCoreExtensions
|
||||
{
|
||||
case ExpressionType.MemberAccess:
|
||||
case ExpressionType.Parameter: break;
|
||||
default: return;
|
||||
default: return false;
|
||||
}
|
||||
switch (memExp.Expression.NodeType)
|
||||
{
|
||||
case ExpressionType.MemberAccess:
|
||||
memExp = memExp.Expression as MemberExpression;
|
||||
if (memExp == null) return;
|
||||
if (memExp == null) return false;
|
||||
parentMemExps.Push(memExp);
|
||||
break;
|
||||
case ExpressionType.Parameter:
|
||||
var tb = fsql.CodeFirst.GetTableByEntity(memExp.Expression.Type);
|
||||
if (tb == null) return;
|
||||
if (tb.ColumnsByCs.TryGetValue(parentMemExps.Pop().Member.Name, out var trycol) == false) return;
|
||||
if (_dicTypes.ContainsKey(trycol.CsType) == false) return;
|
||||
if (tb == null) return false;
|
||||
if (tb.ColumnsByCs.TryGetValue(parentMemExps.Pop().Member.Name, out var trycol) == false) return false;
|
||||
if (_dicTypes.ContainsKey(trycol.CsType) == false) return false;
|
||||
var result = e.FreeParse(Expression.MakeMemberAccess(memExp.Expression, tb.Properties[trycol.CsName]));
|
||||
if (parentMemExps.Any() == false)
|
||||
{
|
||||
e.Result = result;
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
var jsonPath = "";
|
||||
switch (fsql.Ado.DataType)
|
||||
@@ -161,7 +249,7 @@ public static class FreeSqlJsonMapCoreExtensions
|
||||
case DataType.OdbcMySql:
|
||||
case DataType.CustomMySql:
|
||||
StyleJsonExtract();
|
||||
return;
|
||||
return true;
|
||||
case DataType.SqlServer:
|
||||
case DataType.OdbcSqlServer:
|
||||
case DataType.CustomSqlServer:
|
||||
@@ -170,13 +258,13 @@ public static class FreeSqlJsonMapCoreExtensions
|
||||
case DataType.CustomOracle:
|
||||
case DataType.Dameng:
|
||||
StyleJsonValue();
|
||||
return;
|
||||
return true;
|
||||
case DataType.DuckDB:
|
||||
StyleDotAccess();
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
StylePgJson();
|
||||
return;
|
||||
return true;
|
||||
|
||||
void StyleJsonExtract()
|
||||
{
|
||||
|
||||
@@ -93,12 +93,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Extensions.ZeroEnti
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Provider.Duckdb", "Providers\FreeSql.Provider.Duckdb\FreeSql.Provider.Duckdb.csproj", "{02CFB50A-D8C4-470D-AC93-5540D6029430}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Tests.Provider.Duckdb", "FreeSql.Tests\FreeSql.Tests.Provider.Duckdb\FreeSql.Tests.Provider.Duckdb.csproj", "{B9787A81-D537-45ED-B413-61BF03C8FEBE}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Provider.TDengine", "Providers\FreeSql.Provider.TDengine\FreeSql.Provider.TDengine.csproj", "{C89AFB35-AC56-4683-BCB5-13D3522DFED3}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeSql.Extensions.EFModel", "Extensions\FreeSql.Extensions.EFModel\FreeSql.Extensions.EFModel.csproj", "{0BFF3BB8-02ED-460A-A5C8-D9D047791AB0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FreeSql.Tests.Provider.MySqlConnector", "FreeSql.Tests\FreeSql.Tests.Provider.MySqlConnector\FreeSql.Tests.Provider.MySqlConnector.csproj", "{B20EFBC2-CB6A-CD59-32C2-9F2C865CE4A3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -529,18 +529,6 @@ Global
|
||||
{02CFB50A-D8C4-470D-AC93-5540D6029430}.Release|x64.Build.0 = Release|Any CPU
|
||||
{02CFB50A-D8C4-470D-AC93-5540D6029430}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{02CFB50A-D8C4-470D-AC93-5540D6029430}.Release|x86.Build.0 = Release|Any CPU
|
||||
{B9787A81-D537-45ED-B413-61BF03C8FEBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B9787A81-D537-45ED-B413-61BF03C8FEBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B9787A81-D537-45ED-B413-61BF03C8FEBE}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{B9787A81-D537-45ED-B413-61BF03C8FEBE}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{B9787A81-D537-45ED-B413-61BF03C8FEBE}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{B9787A81-D537-45ED-B413-61BF03C8FEBE}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{B9787A81-D537-45ED-B413-61BF03C8FEBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B9787A81-D537-45ED-B413-61BF03C8FEBE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B9787A81-D537-45ED-B413-61BF03C8FEBE}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{B9787A81-D537-45ED-B413-61BF03C8FEBE}.Release|x64.Build.0 = Release|Any CPU
|
||||
{B9787A81-D537-45ED-B413-61BF03C8FEBE}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{B9787A81-D537-45ED-B413-61BF03C8FEBE}.Release|x86.Build.0 = Release|Any CPU
|
||||
{C89AFB35-AC56-4683-BCB5-13D3522DFED3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C89AFB35-AC56-4683-BCB5-13D3522DFED3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C89AFB35-AC56-4683-BCB5-13D3522DFED3}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
@@ -565,6 +553,18 @@ Global
|
||||
{0BFF3BB8-02ED-460A-A5C8-D9D047791AB0}.Release|x64.Build.0 = Release|Any CPU
|
||||
{0BFF3BB8-02ED-460A-A5C8-D9D047791AB0}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{0BFF3BB8-02ED-460A-A5C8-D9D047791AB0}.Release|x86.Build.0 = Release|Any CPU
|
||||
{B20EFBC2-CB6A-CD59-32C2-9F2C865CE4A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B20EFBC2-CB6A-CD59-32C2-9F2C865CE4A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B20EFBC2-CB6A-CD59-32C2-9F2C865CE4A3}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{B20EFBC2-CB6A-CD59-32C2-9F2C865CE4A3}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{B20EFBC2-CB6A-CD59-32C2-9F2C865CE4A3}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{B20EFBC2-CB6A-CD59-32C2-9F2C865CE4A3}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{B20EFBC2-CB6A-CD59-32C2-9F2C865CE4A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B20EFBC2-CB6A-CD59-32C2-9F2C865CE4A3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B20EFBC2-CB6A-CD59-32C2-9F2C865CE4A3}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{B20EFBC2-CB6A-CD59-32C2-9F2C865CE4A3}.Release|x64.Build.0 = Release|Any CPU
|
||||
{B20EFBC2-CB6A-CD59-32C2-9F2C865CE4A3}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{B20EFBC2-CB6A-CD59-32C2-9F2C865CE4A3}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -605,8 +605,8 @@ Global
|
||||
{0BFF3BB8-02ED-460A-A5C8-D9D047791AB0} = {4A92E8A6-9A6D-41A1-9CDA-DE10899648AA}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {089687FA-5D21-40AC-BA8A-AA0D1E1H7F98}
|
||||
RESX_PrefixTranslations = True
|
||||
RESX_NeutralResourcesLanguage = en-US
|
||||
RESX_PrefixTranslations = True
|
||||
SolutionGuid = {089687FA-5D21-40AC-BA8A-AA0D1E1H7F98}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -764,5 +764,13 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.JsonMap\FreeSql.Extensions.JsonMap.csproj" />
|
||||
<ProjectReference Include="..\..\Extensions\FreeSql.Extensions.LazyLoading\FreeSql.Extensions.LazyLoading.csproj" />
|
||||
<ProjectReference Include="..\..\FreeSql.DbContext\FreeSql.DbContext.csproj" />
|
||||
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
|
||||
|
||||
@@ -1,12 +1,54 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Xunit;
|
||||
using static FreeSql.Tests.MySqlConnectorMapType.EnumTest;
|
||||
|
||||
namespace FreeSql.Tests.MySqlConnectorMapType
|
||||
{
|
||||
public class EnumTest
|
||||
{
|
||||
public enum OrgType
|
||||
{
|
||||
Bank = 1,
|
||||
Brokerage,
|
||||
}
|
||||
public record Org2040(OrgType Type, string Id);
|
||||
public class Staff2040
|
||||
{
|
||||
[JsonMap]
|
||||
public Org2040 Org { get; init; }
|
||||
}
|
||||
[Fact]
|
||||
public void Issues2040()
|
||||
{
|
||||
using (var fsql = new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd_mysqlconnector;Charset=utf8;SslMode=none;Max pool size=10;AllowLoadLocalInfile=true;AllowZeroDateTime=True ")
|
||||
.UseAutoSyncStructure(true)
|
||||
.Build())
|
||||
{
|
||||
fsql.UseJsonMap();
|
||||
var sql01 = fsql.Select<Staff2040>().Where(x => x.Org.Type == OrgType.Bank).ToSql();
|
||||
Assert.Equal("SELECT a.`Org` \r\nFROM `Staff2040` a \r\nWHERE (json_extract(a.`Org`,'$.Type') = 1)", sql01);
|
||||
var orgType = OrgType.Bank;
|
||||
var sql02 = fsql.Select<Staff2040>().Where(x => x.Org.Type == orgType).ToSql();
|
||||
Assert.Equal("SELECT a.`Org` \r\nFROM `Staff2040` a \r\nWHERE (json_extract(a.`Org`,'$.Type') = 1)", sql01);
|
||||
|
||||
var sql03 = fsql.Select<Staff2040>().Where(x => new[] { OrgType.Bank, OrgType.Brokerage }.Contains(x.Org.Type)).ToSql();
|
||||
Assert.Equal("SELECT a.`Org` \r\nFROM `Staff2040` a \r\nWHERE (json_extract(a.`Org`,'$.Type') in (1,2))", sql03);
|
||||
var orgTypes1 = new[] { OrgType.Bank, OrgType.Brokerage };
|
||||
var sql04 = fsql.Select<Staff2040>().Where(x => orgTypes1.Contains(x.Org.Type)).ToSql();
|
||||
Assert.Equal("SELECT a.`Org` \r\nFROM `Staff2040` a \r\nWHERE (json_extract(a.`Org`,'$.Type') in (1,2))", sql04);
|
||||
var orgTypes2 = new List<OrgType> { OrgType.Bank, OrgType.Brokerage };
|
||||
var sql05 = fsql.Select<Staff2040>().Where(x => orgTypes2.Contains(x.Org.Type)).ToSql();
|
||||
Assert.Equal("SELECT a.`Org` \r\nFROM `Staff2040` a \r\nWHERE (json_extract(a.`Org`,'$.Type') in (1,2))", sql05);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class EnumTestMap
|
||||
{
|
||||
public Guid id { get; set; }
|
||||
@@ -21,7 +63,7 @@ namespace FreeSql.Tests.MySqlConnectorMapType
|
||||
[Column(MapType = typeof(int?))]
|
||||
public ToStringMapEnum? enumnullable_to_int { get; set; }
|
||||
}
|
||||
public enum ToStringMapEnum { <EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, abc, <EFBFBD><EFBFBD><EFBFBD><EFBFBD> }
|
||||
public enum ToStringMapEnum { 中国人, abc, 香港 }
|
||||
[Fact]
|
||||
public void EnumToString()
|
||||
{
|
||||
@@ -29,11 +71,11 @@ namespace FreeSql.Tests.MySqlConnectorMapType
|
||||
var orm = g.mysql;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
item = new EnumTestMap { enum_to_string = ToStringMapEnum.abc };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
@@ -44,28 +86,28 @@ namespace FreeSql.Tests.MySqlConnectorMapType
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//update all
|
||||
item.enum_to_string = ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
||||
item.enum_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
item.enum_to_string = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>;
|
||||
item.enum_to_string = ToStringMapEnum.中国人;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_string, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_string);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.香港).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enum_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_string);
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_string, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).First();
|
||||
@@ -74,8 +116,8 @@ namespace FreeSql.Tests.MySqlConnectorMapType
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_string == ToStringMapEnum.abc).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
@@ -92,26 +134,26 @@ namespace FreeSql.Tests.MySqlConnectorMapType
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
item = new EnumTestMap { enumnullable_to_string = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD> };
|
||||
item = new EnumTestMap { enumnullable_to_string = ToStringMapEnum.中国人 };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_string);
|
||||
|
||||
//update all
|
||||
item.enumnullable_to_string = ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
||||
item.enumnullable_to_string = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_string, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enumnullable_to_string);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enumnullable_to_string);
|
||||
|
||||
item.enumnullable_to_string = null;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
@@ -134,8 +176,8 @@ namespace FreeSql.Tests.MySqlConnectorMapType
|
||||
Assert.Null(find.enumnullable_to_string);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_string == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
@@ -147,11 +189,11 @@ namespace FreeSql.Tests.MySqlConnectorMapType
|
||||
var orm = g.mysql;
|
||||
var item = new EnumTestMap { };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
var find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_int);
|
||||
|
||||
item = new EnumTestMap { enum_to_int = ToStringMapEnum.abc };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
@@ -162,28 +204,28 @@ namespace FreeSql.Tests.MySqlConnectorMapType
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_int);
|
||||
|
||||
//update all
|
||||
item.enum_to_int = ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
||||
item.enum_to_int = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_int);
|
||||
|
||||
item.enum_to_int = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>;
|
||||
item.enum_to_int = ToStringMapEnum.中国人;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enum_to_int, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enum_to_int);
|
||||
|
||||
//update set
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.香港).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enum_to_int);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enum_to_int);
|
||||
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().Where(a => a.id == item.id).Set(a => a.enum_to_int, ToStringMapEnum.abc).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).First();
|
||||
@@ -192,8 +234,8 @@ namespace FreeSql.Tests.MySqlConnectorMapType
|
||||
Assert.Equal(ToStringMapEnum.abc, find.enum_to_int);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enum_to_int == ToStringMapEnum.abc).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
@@ -210,26 +252,26 @@ namespace FreeSql.Tests.MySqlConnectorMapType
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Null(find.enumnullable_to_int);
|
||||
|
||||
item = new EnumTestMap { enumnullable_to_int = ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD> };
|
||||
item = new EnumTestMap { enumnullable_to_int = ToStringMapEnum.中国人 };
|
||||
Assert.Equal(1, orm.Insert<EnumTestMap>().AppendData(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.中国人).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>, find.enumnullable_to_int);
|
||||
Assert.Equal(ToStringMapEnum.中国人, find.enumnullable_to_int);
|
||||
|
||||
//update all
|
||||
item.enumnullable_to_int = ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
||||
item.enumnullable_to_int = ToStringMapEnum.香港;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First();
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
Assert.Equal(item.enumnullable_to_int, find.enumnullable_to_int);
|
||||
Assert.Equal(ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>, find.enumnullable_to_int);
|
||||
Assert.Equal(ToStringMapEnum.香港, find.enumnullable_to_int);
|
||||
|
||||
item.enumnullable_to_int = null;
|
||||
Assert.Equal(1, orm.Update<EnumTestMap>().SetSource(item).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).First());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).First());
|
||||
find = orm.Select<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).First();
|
||||
Assert.NotNull(find);
|
||||
Assert.Equal(item.id, find.id);
|
||||
@@ -252,8 +294,8 @@ namespace FreeSql.Tests.MySqlConnectorMapType
|
||||
Assert.Null(find.enumnullable_to_int);
|
||||
|
||||
//delete
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.<EFBFBD><EFBFBD><EFBFBD><EFBFBD>).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.中国人).ExecuteAffrows());
|
||||
Assert.Equal(0, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == ToStringMapEnum.香港).ExecuteAffrows());
|
||||
Assert.Equal(1, orm.Delete<EnumTestMap>().Where(a => a.id == item.id && a.enumnullable_to_int == null).ExecuteAffrows());
|
||||
Assert.Null(orm.Select<EnumTestMap>().Where(a => a.id == item.id).First());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user