mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
补充 表达式解析 Equals 为 = #28
This commit is contained in:
parent
8b49dd8f83
commit
b1578f8cdc
@ -32,6 +32,16 @@ namespace FreeSql.Tests.MySqlExpression {
|
|||||||
|
|
||||||
public List<TestTypeInfo> Types { get; set; }
|
public List<TestTypeInfo> Types { get; set; }
|
||||||
}
|
}
|
||||||
|
class TestEqualsGuid {
|
||||||
|
public Guid id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Equals__() {
|
||||||
|
var list = new List<object>();
|
||||||
|
list.Add(select.Where(a => a.Title.Equals("aaa")).ToList());
|
||||||
|
list.Add(g.sqlite.Select<TestEqualsGuid>().Where(a => a.id.Equals(Guid.Empty)).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Empty() {
|
public void Empty() {
|
||||||
|
@ -32,6 +32,17 @@ namespace FreeSql.Tests.OracleExpression {
|
|||||||
|
|
||||||
public List<TestTypeInfo> Types { get; set; }
|
public List<TestTypeInfo> Types { get; set; }
|
||||||
}
|
}
|
||||||
|
class TestEqualsGuid {
|
||||||
|
public Guid id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Equals__() {
|
||||||
|
var list = new List<object>();
|
||||||
|
list.Add(select.Where(a => a.Title.Equals("aaa")).ToList());
|
||||||
|
list.Add(g.oracle.Select<TestEqualsGuid>().Where(a => a.id.Equals(Guid.Empty)).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Empty() {
|
public void Empty() {
|
||||||
|
@ -32,6 +32,17 @@ namespace FreeSql.Tests.PostgreSQLExpression {
|
|||||||
|
|
||||||
public List<TestTypeInfo> Types { get; set; }
|
public List<TestTypeInfo> Types { get; set; }
|
||||||
}
|
}
|
||||||
|
class TestEqualsGuid {
|
||||||
|
public Guid id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Equals__() {
|
||||||
|
var list = new List<object>();
|
||||||
|
list.Add(select.Where(a => a.Title.Equals("aaa")).ToList());
|
||||||
|
list.Add(g.pgsql.Select<TestEqualsGuid>().Where(a => a.id.Equals(Guid.Empty)).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Empty() {
|
public void Empty() {
|
||||||
|
@ -41,6 +41,16 @@ namespace FreeSql.Tests.SqlServerExpression {
|
|||||||
|
|
||||||
public List<TestTypeInfo> Types { get; set; }
|
public List<TestTypeInfo> Types { get; set; }
|
||||||
}
|
}
|
||||||
|
class TestEqualsGuid {
|
||||||
|
public Guid id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Equals__() {
|
||||||
|
var list = new List<object>();
|
||||||
|
list.Add(select.Where(a => a.Title.Equals("aaa")).ToList());
|
||||||
|
list.Add(_sqlserverFixture.SqlServer.Select<TestEqualsGuid>().Where(a => a.id.Equals(Guid.Empty)).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Empty() {
|
public void Empty() {
|
||||||
|
@ -32,6 +32,16 @@ namespace FreeSql.Tests.SqliteExpression {
|
|||||||
|
|
||||||
public List<TestTypeInfo> Types { get; set; }
|
public List<TestTypeInfo> Types { get; set; }
|
||||||
}
|
}
|
||||||
|
class TestEqualsGuid {
|
||||||
|
public Guid id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Equals__() {
|
||||||
|
var list = new List<object>();
|
||||||
|
list.Add(select.Where(a => a.Title.Equals("aaa")).ToList());
|
||||||
|
list.Add(g.sqlite.Select<TestEqualsGuid>().Where(a => a.id.Equals(Guid.Empty)).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Empty() {
|
public void Empty() {
|
||||||
|
@ -50,7 +50,7 @@ public class g {
|
|||||||
Console.WriteLine(traceLog);
|
Console.WriteLine(traceLog);
|
||||||
}) //监听SQL命令对象,在执行后
|
}) //监听SQL命令对象,在执行后
|
||||||
.Build());
|
.Build());
|
||||||
public static IFreeSql oracle = oracleLazy.Value;
|
public static IFreeSql oracle => oracleLazy.Value;
|
||||||
|
|
||||||
static Lazy<IFreeSql> sqliteLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
static Lazy<IFreeSql> sqliteLazy = new Lazy<IFreeSql>(() => new FreeSql.FreeSqlBuilder()
|
||||||
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Attachs=xxxtb.db;Pooling=true;Max Pool Size=10")
|
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Attachs=xxxtb.db;Pooling=true;Max Pool Size=10")
|
||||||
@ -64,5 +64,5 @@ public class g {
|
|||||||
Console.WriteLine(traceLog);
|
Console.WriteLine(traceLog);
|
||||||
}) //监听SQL命令对象,在执行后
|
}) //监听SQL命令对象,在执行后
|
||||||
.Build());
|
.Build());
|
||||||
public static IFreeSql sqlite = sqliteLazy.Value;
|
public static IFreeSql sqlite => sqliteLazy.Value;
|
||||||
}
|
}
|
||||||
|
@ -306,6 +306,18 @@ namespace FreeSql.Internal {
|
|||||||
return $"case when {ExpressionLambdaToSql(condExp.Test, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style)} then {ExpressionLambdaToSql(condExp.IfTrue, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style)} else {ExpressionLambdaToSql(condExp.IfFalse, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style)} end";
|
return $"case when {ExpressionLambdaToSql(condExp.Test, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style)} then {ExpressionLambdaToSql(condExp.IfTrue, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style)} else {ExpressionLambdaToSql(condExp.IfFalse, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style)} end";
|
||||||
case ExpressionType.Call:
|
case ExpressionType.Call:
|
||||||
var exp3 = exp as MethodCallExpression;
|
var exp3 = exp as MethodCallExpression;
|
||||||
|
if (exp3.Method.Name == "Equals" && exp3.Object != null && exp3.Arguments.Count > 0) {
|
||||||
|
var tmptryoper = "=";
|
||||||
|
var tmpleft = ExpressionLambdaToSql(exp3.Object, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style);
|
||||||
|
var tmpright = ExpressionLambdaToSql(exp3.Arguments[0], _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style);
|
||||||
|
if (tmpleft == "NULL") {
|
||||||
|
var tmp33 = tmpright;
|
||||||
|
tmpright = tmpleft;
|
||||||
|
tmpleft = tmp33;
|
||||||
|
}
|
||||||
|
if (tmpright == "NULL") tmptryoper = " IS ";
|
||||||
|
return $"{tmpleft}{tmptryoper}{tmpright}";
|
||||||
|
}
|
||||||
var callType = exp3.Object?.Type ?? exp3.Method.DeclaringType;
|
var callType = exp3.Object?.Type ?? exp3.Method.DeclaringType;
|
||||||
switch (callType.FullName) {
|
switch (callType.FullName) {
|
||||||
case "System.String": return ExpressionLambdaToSqlCallString(exp3, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style);
|
case "System.String": return ExpressionLambdaToSqlCallString(exp3, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user