mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
优化 vb.net 匿名类判断
This commit is contained in:
parent
8da3c16c40
commit
1ab1d16e53
@ -130,6 +130,13 @@
|
|||||||
清空状态数据
|
清空状态数据
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
|
||||||
|
<summary>
|
||||||
|
根据 lambda 条件删除数据
|
||||||
|
</summary>
|
||||||
|
<param name="predicate"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:FreeSql.DbSet`1.Add(`0)">
|
<member name="M:FreeSql.DbSet`1.Add(`0)">
|
||||||
<summary>
|
<summary>
|
||||||
添加
|
添加
|
||||||
@ -520,5 +527,14 @@
|
|||||||
<param name="that"></param>
|
<param name="that"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||||
|
<summary>
|
||||||
|
批量注入 Repository,可以参考代码自行调整
|
||||||
|
</summary>
|
||||||
|
<param name="services"></param>
|
||||||
|
<param name="globalDataFilter"></param>
|
||||||
|
<param name="assemblies"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
@ -20,20 +20,81 @@ WHERE (a.[Id] = 100 AND a.[Title] IS NULL)", sql)
|
|||||||
|
|
||||||
REM VB.net ±í´ïʽ½âÎö¼æÈÝÐÔ²âÊÔ
|
REM VB.net ±í´ïʽ½âÎö¼æÈÝÐÔ²âÊÔ
|
||||||
Dim id As Integer = 100
|
Dim id As Integer = 100
|
||||||
|
|
||||||
|
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||||
|
FROM [Testvb] a
|
||||||
|
WHERE (a.[Id] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = 100).ToSql())
|
||||||
Dim List1 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = 100).ToList()
|
Dim List1 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = 100).ToList()
|
||||||
|
|
||||||
|
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||||
|
FROM [Testvb] a
|
||||||
|
WHERE (a.[Id] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = id).ToSql())
|
||||||
Dim List2 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = id).ToList()
|
Dim List2 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = id).ToList()
|
||||||
|
|
||||||
|
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||||
|
FROM [Testvb] a
|
||||||
|
WHERE (a.[IdNullable] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = 100).ToSql())
|
||||||
Dim List11 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = 100).ToList()
|
Dim List11 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = 100).ToList()
|
||||||
|
|
||||||
|
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||||
|
FROM [Testvb] a
|
||||||
|
WHERE (a.[IdNullable] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = id).ToSql())
|
||||||
Dim List22 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = id).ToList()
|
Dim List22 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = id).ToList()
|
||||||
|
|
||||||
Dim idNullable As Integer? = 100
|
Dim idNullable As Integer? = 100
|
||||||
|
|
||||||
|
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||||
|
FROM [Testvb] a
|
||||||
|
WHERE (a.[IdNullable] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = idNullable).ToSql())
|
||||||
Dim List222 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = idNullable).ToList()
|
Dim List222 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = idNullable).ToList()
|
||||||
|
|
||||||
|
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||||
|
FROM [Testvb] a
|
||||||
|
WHERE (a.[Title] = N'xxx')", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = "xxx").ToSql())
|
||||||
Dim List3 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = "xxx").ToList()
|
Dim List3 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = "xxx").ToList()
|
||||||
|
|
||||||
Dim title As String = "xxx"
|
Dim title As String = "xxx"
|
||||||
|
|
||||||
|
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||||
|
FROM [Testvb] a
|
||||||
|
WHERE (a.[Title] = N'xxx')", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = title).ToSql())
|
||||||
Dim List4 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = title).ToList()
|
Dim List4 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = title).ToList()
|
||||||
|
|
||||||
|
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||||
|
FROM [Testvb] a
|
||||||
|
WHERE (a.[Title] <> N'xxx')", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> "xxx").ToSql())
|
||||||
Dim List5 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> "xxx").ToList()
|
Dim List5 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> "xxx").ToList()
|
||||||
|
|
||||||
|
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||||
|
FROM [Testvb] a
|
||||||
|
WHERE (a.[Title] <> N'xxx')", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> title).ToSql())
|
||||||
Dim List6 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> title).ToList()
|
Dim List6 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> title).ToList()
|
||||||
|
|
||||||
Dim List7 = g.sqlserver.Select(Of Testvb).ToList(Function(a) New With {a, a.Id, a.Title})
|
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||||
Dim List8 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IsDeleted).ToList()
|
FROM [Testvb] a
|
||||||
|
WHERE (a.[Title] = a.[Title])", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = a.Title).ToSql())
|
||||||
|
Dim List7 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = a.Title).ToList()
|
||||||
|
|
||||||
|
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||||
|
FROM [Testvb] a
|
||||||
|
WHERE (a.[Title] <> a.[Title])", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> a.Title).ToSql())
|
||||||
|
Dim List71 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = a.Title).ToList()
|
||||||
|
|
||||||
|
Assert.Equal("SELECT a.[Id] as1, a.[Title] as2, a.[IsDeleted] as3, a.[IdNullable] as4, a.[Id] as5, a.[Title] as6
|
||||||
|
FROM [Testvb] a", g.sqlserver.Select(Of Testvb).ToSql(Function(a) New With {a, a.Id, a.Title}))
|
||||||
|
Dim List8 = g.sqlserver.Select(Of Testvb).ToList(Function(a) New With {a, a.Id, a.Title})
|
||||||
|
|
||||||
|
Assert.Equal("SELECT a.[Id] as1, a.[Title] as2
|
||||||
|
FROM [Testvb] a", g.sqlserver.Select(Of Testvb).ToSql(Function(a) New With {a.Id, a.Title}))
|
||||||
|
Dim List81 = g.sqlserver.Select(Of Testvb).ToList(Function(a) New With {a.Id, a.Title})
|
||||||
|
|
||||||
|
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||||
|
FROM [Testvb] a
|
||||||
|
WHERE (a.[IsDeleted] = 1)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.IsDeleted).ToSql())
|
||||||
|
Dim List9 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IsDeleted).ToList()
|
||||||
|
|
||||||
|
REM Microsoft.VisualBasic.CompilerServices.Operators.CompareObjectEqual(
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
g.sqlserver.Delete(Of Testvb2).Where("1=1").ExecuteAffrows()
|
g.sqlserver.Delete(Of Testvb2).Where("1=1").ExecuteAffrows()
|
||||||
@ -48,7 +109,7 @@ WHERE (a.[Id] = 100 AND a.[Title] IS NULL)", sql)
|
|||||||
g.sqlserver.Insert(New Testvb2 With {.Id = 5, .TestvbId = 2, .Context = "Context22"}).ExecuteAffrows()
|
g.sqlserver.Insert(New Testvb2 With {.Id = 5, .TestvbId = 2, .Context = "Context22"}).ExecuteAffrows()
|
||||||
g.sqlserver.Insert(New Testvb2 With {.Id = 6, .TestvbId = 3, .Context = "Context31"}).ExecuteAffrows()
|
g.sqlserver.Insert(New Testvb2 With {.Id = 6, .TestvbId = 3, .Context = "Context31"}).ExecuteAffrows()
|
||||||
|
|
||||||
Dim List9 = g.sqlserver.Select(Of Testvb).IncludeMany(Function(a) a.Testvb2s).ToList()
|
Dim List10 = g.sqlserver.Select(Of Testvb).IncludeMany(Function(a) a.Testvb2s).ToList()
|
||||||
|
|
||||||
BaseEntity.Initialization(g.sqlserver, Nothing)
|
BaseEntity.Initialization(g.sqlserver, Nothing)
|
||||||
Dim cowR As CowRecord = New CowRecord
|
Dim cowR As CowRecord = New CowRecord
|
||||||
|
@ -44,7 +44,7 @@ public static partial class FreeSqlGlobalExtensions
|
|||||||
public static bool IsIntegerType(this Type that) => that == null ? false : (_dicIsNumberType.Value.TryGetValue(that, out var tryval) ? tryval : false);
|
public static bool IsIntegerType(this Type that) => that == null ? false : (_dicIsNumberType.Value.TryGetValue(that, out var tryval) ? tryval : false);
|
||||||
public static bool IsNumberType(this Type that) => that == null ? false : _dicIsNumberType.Value.ContainsKey(that);
|
public static bool IsNumberType(this Type that) => that == null ? false : _dicIsNumberType.Value.ContainsKey(that);
|
||||||
public static bool IsNullableType(this Type that) => that.IsArray == false && that?.FullName.StartsWith("System.Nullable`1[") == true;
|
public static bool IsNullableType(this Type that) => that.IsArray == false && that?.FullName.StartsWith("System.Nullable`1[") == true;
|
||||||
public static bool IsAnonymousType(this Type that) => that?.FullName.StartsWith("<>f__AnonymousType") == true;
|
public static bool IsAnonymousType(this Type that) => that == null ? false : (that.FullName.StartsWith("<>f__AnonymousType") || that.FullName.StartsWith("VB$AnonymousType"));
|
||||||
public static bool IsArrayOrList(this Type that) => that == null ? false : (that.IsArray || typeof(IList).IsAssignableFrom(that));
|
public static bool IsArrayOrList(this Type that) => that == null ? false : (that.IsArray || typeof(IList).IsAssignableFrom(that));
|
||||||
public static Type NullableTypeOrThis(this Type that) => that?.IsNullableType() == true ? that.GetGenericArguments().First() : that;
|
public static Type NullableTypeOrThis(this Type that) => that?.IsNullableType() == true ? that.GetGenericArguments().First() : that;
|
||||||
internal static string NotNullAndConcat(this string that, params object[] args) => string.IsNullOrEmpty(that) ? null : string.Concat(new object[] { that }.Concat(args));
|
internal static string NotNullAndConcat(this string that, params object[] args) => string.IsNullOrEmpty(that) ? null : string.Concat(new object[] { that }.Concat(args));
|
||||||
|
@ -465,20 +465,6 @@ namespace FreeSql.Internal
|
|||||||
}
|
}
|
||||||
public string ExpressionBinary(string oper, Expression leftExp, Expression rightExp, ExpTSC tsc)
|
public string ExpressionBinary(string oper, Expression leftExp, Expression rightExp, ExpTSC tsc)
|
||||||
{
|
{
|
||||||
if (leftExp.NodeType == ExpressionType.Call &&
|
|
||||||
rightExp.NodeType == ExpressionType.Constant &&
|
|
||||||
new[] { "=", "<>" }.Contains(oper))
|
|
||||||
{
|
|
||||||
var leftExpCall = leftExp as MethodCallExpression;
|
|
||||||
//vb 语法,将字符串比较转换为了 CompareString
|
|
||||||
if (leftExpCall.Method.Name == "CompareString" &&
|
|
||||||
leftExpCall.Method.DeclaringType?.FullName == "Microsoft.VisualBasic.CompilerServices.Operators" &&
|
|
||||||
leftExpCall.Arguments.Count == 3 &&
|
|
||||||
leftExpCall.Arguments[2].Type == typeof(bool) &&
|
|
||||||
rightExp.Type == typeof(int) &&
|
|
||||||
(int)(rightExp as ConstantExpression).Value == 0)
|
|
||||||
return ExpressionBinary(oper, leftExpCall.Arguments[0], leftExpCall.Arguments[1], tsc);
|
|
||||||
}
|
|
||||||
switch (oper)
|
switch (oper)
|
||||||
{
|
{
|
||||||
case "OR":
|
case "OR":
|
||||||
@ -498,6 +484,19 @@ namespace FreeSql.Internal
|
|||||||
return $"({ExpressionLambdaToSql(leftExp, tsc)} {oper} {ExpressionLambdaToSql(rightExp, tsc)})";
|
return $"({ExpressionLambdaToSql(leftExp, tsc)} {oper} {ExpressionLambdaToSql(rightExp, tsc)})";
|
||||||
case "=":
|
case "=":
|
||||||
case "<>":
|
case "<>":
|
||||||
|
if (leftExp.NodeType == ExpressionType.Call &&
|
||||||
|
rightExp.NodeType == ExpressionType.Constant)
|
||||||
|
{
|
||||||
|
var leftExpCall = leftExp as MethodCallExpression;
|
||||||
|
//vb 语法,将字符串比较转换为了 CompareString
|
||||||
|
if (leftExpCall.Method.Name == "CompareString" &&
|
||||||
|
leftExpCall.Method.DeclaringType?.FullName == "Microsoft.VisualBasic.CompilerServices.Operators" &&
|
||||||
|
leftExpCall.Arguments.Count == 3 &&
|
||||||
|
leftExpCall.Arguments[2].Type == typeof(bool) &&
|
||||||
|
rightExp.Type == typeof(int) &&
|
||||||
|
(int)(rightExp as ConstantExpression).Value == 0)
|
||||||
|
return ExpressionBinary(oper, leftExpCall.Arguments[0], leftExpCall.Arguments[1], tsc);
|
||||||
|
}
|
||||||
var exptb = _common.GetTableByEntity(leftExp.Type);
|
var exptb = _common.GetTableByEntity(leftExp.Type);
|
||||||
if (exptb?.Properties.Any() == true) leftExp = Expression.MakeMemberAccess(leftExp, exptb.Properties[(exptb.Primarys.FirstOrDefault() ?? exptb.Columns.FirstOrDefault().Value)?.CsName]);
|
if (exptb?.Properties.Any() == true) leftExp = Expression.MakeMemberAccess(leftExp, exptb.Properties[(exptb.Primarys.FirstOrDefault() ?? exptb.Columns.FirstOrDefault().Value)?.CsName]);
|
||||||
exptb = _common.GetTableByEntity(leftExp.Type);
|
exptb = _common.GetTableByEntity(leftExp.Type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user