mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 修复 Expression OrElse 两侧括号丢失的 bug;
- 修复 Expression DateTime 类型 CompareTo 在 MySql/SqlServer 下的 bug;
This commit is contained in:
parent
9dd85f33f9
commit
b16218d779
214
Examples/benchmarker/Program.cs
Normal file
214
Examples/benchmarker/Program.cs
Normal file
@ -0,0 +1,214 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Running;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
//using SqlSugar;
|
||||
|
||||
namespace FreeSql.Bechmarker {
|
||||
|
||||
public class Program {
|
||||
public static void Main(string[] args) {
|
||||
var summaryInsert = BenchmarkRunner.Run<OrmVsInsert>();
|
||||
var summarySelect = BenchmarkRunner.Run<OrmVsSelect>();
|
||||
var summaryUpdate = BenchmarkRunner.Run<OrmVsUpdate>();
|
||||
}
|
||||
}
|
||||
|
||||
public class Orm {
|
||||
public static IFreeSql fsql = new FreeSql.FreeSqlBuilder()
|
||||
.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=20")
|
||||
//.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=20")
|
||||
.UseAutoSyncStructure(false)
|
||||
.UseNoneCommandParameter(true)
|
||||
//.UseConfigEntityFromDbFirst(true)
|
||||
.Build();
|
||||
|
||||
//public static SqlSugarClient sugar {
|
||||
// get => new SqlSugarClient(new ConnectionConfig() {
|
||||
// //不欺负,让连接池100个最小
|
||||
// ConnectionString = "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Min Pool Size=20;Max Pool Size=20",
|
||||
// DbType = DbType.SqlServer,
|
||||
// //ConnectionString = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Min Pool Size=20;Max Pool Size=20",
|
||||
// //DbType = DbType.MySql,
|
||||
// IsAutoCloseConnection = true,
|
||||
// InitKeyType = InitKeyType.Attribute
|
||||
// });
|
||||
//}
|
||||
}
|
||||
class SongContext : DbContext {
|
||||
public DbSet<Song> Songs { get; set; }
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
|
||||
optionsBuilder.UseSqlServer(@"Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Min Pool Size=21;Max Pool Size=21");
|
||||
//optionsBuilder.UseMySql("Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;Min Pool Size=21;Max Pool Size=21");
|
||||
}
|
||||
}
|
||||
|
||||
[CoreJob]
|
||||
[RPlotExporter, RankColumn]
|
||||
public class OrmVsInsert {
|
||||
public IEnumerable<Song> songs;
|
||||
|
||||
[Params(1, 500, 1000, 5000, 10000, 50000, 100000)]
|
||||
public int size;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup() {
|
||||
Orm.fsql.CodeFirst.SyncStructure(typeof(Song), typeof(Song_tag), typeof(Tag));
|
||||
//Orm.sugar.CodeFirst.InitTables(typeof(Song), typeof(Song_tag), typeof(Tag));
|
||||
//sugar创建表失败:SqlSugar.SqlSugarException: Sequence contains no elements
|
||||
|
||||
//测试前清空数据
|
||||
Orm.fsql.Delete<Song>().Where(a => a.Id > 0).ExecuteAffrows();
|
||||
//Orm.sugar.Deleteable<Song>().Where(a => a.Id > 0).ExecuteCommand();
|
||||
Orm.fsql.Ado.ExecuteNonQuery("delete from efcore_song");
|
||||
|
||||
songs = Enumerable.Range(0, size).Select(a => new Song {
|
||||
Create_time = DateTime.Now,
|
||||
Is_deleted = false,
|
||||
Title = $"Insert_{a}",
|
||||
Url = $"Url_{a}"
|
||||
});
|
||||
|
||||
//预热
|
||||
Orm.fsql.Insert(songs.First()).ExecuteAffrows();
|
||||
//Orm.sugar.Insertable(songs.First()).ExecuteCommand();
|
||||
using (var db = new SongContext()) {
|
||||
//db.Configuration.AutoDetectChangesEnabled = false;
|
||||
db.Songs.AddRange(songs.First());
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int FreeSqlInsert() => Orm.fsql.Insert(songs).ExecuteAffrows();
|
||||
|
||||
//[Benchmark]
|
||||
//public int SqlSugarInsert() => Orm.sugar.Insertable(songs.ToArray()).ExecuteCommand();
|
||||
|
||||
[Benchmark]
|
||||
public int EfCoreInsert() {
|
||||
using (var db = new SongContext()) {
|
||||
//db.Configuration.AutoDetectChangesEnabled = false;
|
||||
db.Songs.AddRange(songs.ToArray());
|
||||
return db.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CoreJob]
|
||||
[RPlotExporter, RankColumn]
|
||||
public class OrmVsUpdate {
|
||||
public List<Song> songs;
|
||||
|
||||
[Params(1, 500, 1000, 5000, 10000, 50000, 100000)]
|
||||
public int size;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup() {
|
||||
songs = Orm.fsql.Select<Song>().Limit(size).ToList();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int FreeSqlUpdate() => Orm.fsql.Update<Song>().SetSource(songs).ExecuteAffrows();
|
||||
|
||||
//[Benchmark]
|
||||
//public int SqlSugarUpdate() => Orm.sugar.Updateable(songs).ExecuteCommand();
|
||||
|
||||
[Benchmark]
|
||||
public int EfCoreUpdate() {
|
||||
using (var db = new SongContext()) {
|
||||
//db.Configuration.AutoDetectChangesEnabled = false;
|
||||
db.Songs.UpdateRange(songs.ToArray());
|
||||
return db.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CoreJob]
|
||||
[RPlotExporter, RankColumn]
|
||||
public class OrmVsSelect {
|
||||
|
||||
[Params(1, 500, 1000, 5000, 10000, 50000, 100000)]
|
||||
public int size;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup() {
|
||||
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public List<Song> FreeSqlSelect() => Orm.fsql.Select<Song>().Limit(size).ToList();
|
||||
|
||||
//[Benchmark]
|
||||
//public List<Song> SqlSugarSelect() => Orm.sugar.Queryable<Song>().Take(size).ToList();
|
||||
|
||||
[Benchmark]
|
||||
public List<Song> EfCoreSelect() {
|
||||
using (var db = new SongContext()) {
|
||||
return db.Songs.Take(size).AsNoTracking().ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[FreeSql.DataAnnotations.Table(Name = "freesql_song")]
|
||||
//[SugarTable("sugar_song")]
|
||||
[Table("efcore_song")]
|
||||
public class Song {
|
||||
[FreeSql.DataAnnotations.Column(IsIdentity = true)]
|
||||
//[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
public DateTime? Create_time { get; set; }
|
||||
public bool? Is_deleted { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Url { get; set; }
|
||||
|
||||
//[SugarColumn(IsIgnore = true)]
|
||||
[NotMapped]
|
||||
public virtual ICollection<Tag> Tags { get; set; }
|
||||
}
|
||||
[FreeSql.DataAnnotations.Table(Name = "freesql_song_tag")]
|
||||
//[SugarTable("sugar_song_tag")]
|
||||
[Table("efcore_song_tag")]
|
||||
public class Song_tag {
|
||||
public int Song_id { get; set; }
|
||||
//[SugarColumn(IsIgnore = true)]
|
||||
[NotMapped]
|
||||
public virtual Song Song { get; set; }
|
||||
|
||||
public int Tag_id { get; set; }
|
||||
//[SugarColumn(IsIgnore = true)]
|
||||
[NotMapped]
|
||||
public virtual Tag Tag { get; set; }
|
||||
}
|
||||
[FreeSql.DataAnnotations.Table(Name = "freesql_tag")]
|
||||
//[SugarTable("sugar_tag")]
|
||||
[Table("efcore_tag")]
|
||||
public class Tag {
|
||||
[FreeSql.DataAnnotations.Column(IsIdentity = true)]
|
||||
//[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
public int? Parent_id { get; set; }
|
||||
//[SugarColumn(IsIgnore = true)]
|
||||
[NotMapped]
|
||||
public virtual Tag Parent { get; set; }
|
||||
|
||||
public decimal? Ddd { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
//[SugarColumn(IsIgnore = true)]
|
||||
[NotMapped]
|
||||
public virtual ICollection<Song> Songs { get; set; }
|
||||
//[SugarColumn(IsIgnore = true)]
|
||||
[NotMapped]
|
||||
public virtual ICollection<Tag> Tags { get; set; }
|
||||
}
|
||||
}
|
||||
|
18
Examples/benchmarker/benchmarker.csproj
Normal file
18
Examples/benchmarker/benchmarker.csproj
Normal file
@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\FreeSql\FreeSql.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -536,6 +536,10 @@ namespace FreeSql.Tests.MySql {
|
||||
}
|
||||
[Fact]
|
||||
public void Where() {
|
||||
|
||||
var sqltmp1 = select.Where(a => a.Id == 0 && (a.Title == "x" || a.Title == "y") && a.Clicks == 1).ToSql();
|
||||
var sqltmp2 = select.Where(a => a.Id.Equals(true) && (a.Title.Equals("x") || a.Title.Equals("y")) && a.Clicks.Equals(1)).ToSql();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
var query = select.Where(a => a.Id == 10);
|
||||
var sql = query.ToSql().Replace("\r\n", "");
|
||||
@ -544,7 +548,7 @@ namespace FreeSql.Tests.MySql {
|
||||
|
||||
query = select.Where(a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a WHERE (a.`Id` = 10 AND a.`Id` > 10 OR a.`Clicks` > 100)", sql);
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a WHERE ((a.`Id` = 10 AND a.`Id` > 10 OR a.`Clicks` > 100))", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Id == 10).Where(a => a.Clicks > 100);
|
||||
@ -607,7 +611,7 @@ namespace FreeSql.Tests.MySql {
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a WHERE (a.`Id` = 10 AND a.`Id` > 10 OR a.`Clicks` > 100)", sql);
|
||||
Assert.Equal("SELECT a.`Id`, a.`Clicks`, a.`TypeGuid`, a.`Title`, a.`CreateTime` FROM `tb_topic` a WHERE ((a.`Id` = 10 AND a.`Id` > 10 OR a.`Clicks` > 100))", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10).WhereIf(true, a => a.Clicks > 100);
|
||||
|
@ -433,6 +433,9 @@ namespace FreeSql.Tests.Oracle {
|
||||
}
|
||||
[Fact]
|
||||
public void Where() {
|
||||
var sqltmp1 = select.Where(a => a.Id == 0 && (a.Title == "x" || a.Title == "y") && a.Clicks == 1).ToSql();
|
||||
var sqltmp2 = select.Where(a => a.Id.Equals(true) && (a.Title.Equals("x") || a.Title.Equals("y")) && a.Clicks.Equals(1)).ToSql();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
var query = select.Where(a => a.Id == 10);
|
||||
var sql = query.ToSql().Replace("\r\n", "");
|
||||
@ -441,7 +444,7 @@ namespace FreeSql.Tests.Oracle {
|
||||
|
||||
query = select.Where(a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10 AND a.\"ID\" > 10 OR a.\"CLICKS\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE ((a.\"ID\" = 10 AND a.\"ID\" > 10 OR a.\"CLICKS\" > 100))", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Id == 10).Where(a => a.Clicks > 100);
|
||||
@ -504,7 +507,7 @@ namespace FreeSql.Tests.Oracle {
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE (a.\"ID\" = 10 AND a.\"ID\" > 10 OR a.\"CLICKS\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"ID\", a.\"CLICKS\", a.\"TYPEGUID\", a.\"TITLE\", a.\"CREATETIME\" FROM \"TB_TOPIC22\" a WHERE ((a.\"ID\" = 10 AND a.\"ID\" > 10 OR a.\"CLICKS\" > 100))", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10).WhereIf(true, a => a.Clicks > 100);
|
||||
|
@ -504,6 +504,9 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
}
|
||||
[Fact]
|
||||
public void Where() {
|
||||
var sqltmp1 = select.Where(a => a.Id == 0 && (a.Title == "x" || a.Title == "y") && a.Clicks == 1).ToSql();
|
||||
var sqltmp2 = select.Where(a => a.Id.Equals(true) && (a.Title.Equals("x") || a.Title.Equals("y")) && a.Clicks.Equals(1)).ToSql();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
var query = select.Where(a => a.Id == 10);
|
||||
var sql = query.ToSql().Replace("\r\n", "");
|
||||
@ -512,7 +515,7 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
|
||||
query = select.Where(a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10 AND a.\"id\" > 10 OR a.\"clicks\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE ((a.\"id\" = 10 AND a.\"id\" > 10 OR a.\"clicks\" > 100))", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Id == 10).Where(a => a.Clicks > 100);
|
||||
@ -575,7 +578,7 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE (a.\"id\" = 10 AND a.\"id\" > 10 OR a.\"clicks\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"id\", a.\"clicks\", a.\"typeguid\", a.\"title\", a.\"createtime\" FROM \"tb_topic\" a WHERE ((a.\"id\" = 10 AND a.\"id\" > 10 OR a.\"clicks\" > 100))", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10).WhereIf(true, a => a.Clicks > 100);
|
||||
|
@ -435,6 +435,9 @@ namespace FreeSql.Tests.SqlServer {
|
||||
}
|
||||
[Fact]
|
||||
public void Where() {
|
||||
var sqltmp1 = select.Where(a => a.Id == 0 && (a.Title == "x" || a.Title == "y") && a.Clicks == 1).ToSql();
|
||||
var sqltmp2 = select.Where(a => a.Id.Equals(true) && (a.Title.Equals("x") || a.Title.Equals("y")) && a.Clicks.Equals(1)).ToSql();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
var query = select.Where(a => a.Id == 10);
|
||||
var sql = query.ToSql().Replace("\r\n", "");
|
||||
@ -443,7 +446,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
query = select.Where(a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a WHERE (a.[Id] = 10 AND a.[Id] > 10 OR a.[Clicks] > 100)", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a WHERE ((a.[Id] = 10 AND a.[Id] > 10 OR a.[Clicks] > 100))", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Id == 10).Where(a => a.Clicks > 100);
|
||||
@ -506,7 +509,7 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a WHERE (a.[Id] = 10 AND a.[Id] > 10 OR a.[Clicks] > 100)", sql);
|
||||
Assert.Equal("SELECT a.[Id], a.[Clicks], a.[TypeGuid], a.[Title], a.[CreateTime] FROM [tb_topic22] a WHERE ((a.[Id] = 10 AND a.[Id] > 10 OR a.[Clicks] > 100))", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10).WhereIf(true, a => a.Clicks > 100);
|
||||
|
@ -379,6 +379,9 @@ namespace FreeSql.Tests.Sqlite {
|
||||
}
|
||||
[Fact]
|
||||
public void Where() {
|
||||
var sqltmp1 = select.Where(a => a.Id == 0 && (a.Title == "x" || a.Title == "y") && a.Clicks == 1).ToSql();
|
||||
var sqltmp2 = select.Where(a => a.Id.Equals(true) && (a.Title.Equals("x") || a.Title.Equals("y")) && a.Clicks.Equals(1)).ToSql();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a.Type<70><65>a.Type.Parent <20><><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
var query = select.Where(a => a.Id == 10);
|
||||
var sql = query.ToSql().Replace("\r\n", "");
|
||||
@ -387,7 +390,7 @@ namespace FreeSql.Tests.Sqlite {
|
||||
|
||||
query = select.Where(a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a WHERE (a.\"Id\" = 10 AND a.\"Id\" > 10 OR a.\"Clicks\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a WHERE ((a.\"Id\" = 10 AND a.\"Id\" > 10 OR a.\"Clicks\" > 100))", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.Where(a => a.Id == 10).Where(a => a.Clicks > 100);
|
||||
@ -450,7 +453,7 @@ namespace FreeSql.Tests.Sqlite {
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10 && a.Id > 10 || a.Clicks > 100);
|
||||
sql = query.ToSql().Replace("\r\n", "");
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a WHERE (a.\"Id\" = 10 AND a.\"Id\" > 10 OR a.\"Clicks\" > 100)", sql);
|
||||
Assert.Equal("SELECT a.\"Id\", a.\"Clicks\", a.\"TypeGuid\", a.\"Title\", a.\"CreateTime\" FROM \"tb_topic22\" a WHERE ((a.\"Id\" = 10 AND a.\"Id\" > 10 OR a.\"Clicks\" > 100))", sql);
|
||||
query.ToList();
|
||||
|
||||
query = select.WhereIf(true, a => a.Id == 10).WhereIf(true, a => a.Clicks > 100);
|
||||
|
15
FreeSql.sln
15
FreeSql.sln
@ -24,6 +24,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "efcore_to_freesql", "Exampl
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "orm_vs", "Examples\orm_vs\orm_vs.csproj", "{1A5EC2EB-8C2B-4547-8AC6-EB5C0DE0CA81}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "benchmarker", "Examples\benchmarker\benchmarker.csproj", "{E7405816-F32A-4F3E-AD76-29129962C6AA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -118,6 +120,18 @@ Global
|
||||
{1A5EC2EB-8C2B-4547-8AC6-EB5C0DE0CA81}.Release|x64.Build.0 = Release|Any CPU
|
||||
{1A5EC2EB-8C2B-4547-8AC6-EB5C0DE0CA81}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{1A5EC2EB-8C2B-4547-8AC6-EB5C0DE0CA81}.Release|x86.Build.0 = Release|Any CPU
|
||||
{E7405816-F32A-4F3E-AD76-29129962C6AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E7405816-F32A-4F3E-AD76-29129962C6AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E7405816-F32A-4F3E-AD76-29129962C6AA}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{E7405816-F32A-4F3E-AD76-29129962C6AA}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{E7405816-F32A-4F3E-AD76-29129962C6AA}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{E7405816-F32A-4F3E-AD76-29129962C6AA}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{E7405816-F32A-4F3E-AD76-29129962C6AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E7405816-F32A-4F3E-AD76-29129962C6AA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E7405816-F32A-4F3E-AD76-29129962C6AA}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{E7405816-F32A-4F3E-AD76-29129962C6AA}.Release|x64.Build.0 = Release|Any CPU
|
||||
{E7405816-F32A-4F3E-AD76-29129962C6AA}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{E7405816-F32A-4F3E-AD76-29129962C6AA}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -126,6 +140,7 @@ Global
|
||||
{83D10565-AF9D-4EDC-8FB8-8C962A843F97} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B}
|
||||
{B93981B8-3295-4EDD-B314-BCA77B6BF37A} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B}
|
||||
{1A5EC2EB-8C2B-4547-8AC6-EB5C0DE0CA81} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B}
|
||||
{E7405816-F32A-4F3E-AD76-29129962C6AA} = {94C8A78D-AA15-47B2-A348-530CD86BFC1B}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {089687FD-5D25-40AB-BA8A-A10D1E137F98}
|
||||
|
@ -771,10 +771,11 @@ namespace FreeSql.Internal {
|
||||
if (string.IsNullOrEmpty(other99Exp) == false) return other99Exp;
|
||||
return "";
|
||||
}
|
||||
if (expBinary.NodeType == ExpressionType.Coalesce) {
|
||||
return _common.IsNull(
|
||||
ExpressionLambdaToSql(expBinary.Left, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style),
|
||||
ExpressionLambdaToSql(expBinary.Right, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style));
|
||||
switch (expBinary.NodeType) {
|
||||
case ExpressionType.Coalesce:
|
||||
return _common.IsNull(ExpressionLambdaToSql(expBinary.Left, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style), ExpressionLambdaToSql(expBinary.Right, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style));
|
||||
case ExpressionType.OrElse:
|
||||
return $"({ExpressionLambdaToSql(expBinary.Left, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style)} OR {ExpressionLambdaToSql(expBinary.Right, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style)})";
|
||||
}
|
||||
if (dicExpressionOperator.TryGetValue(expBinary.NodeType, out var tryoper) == false) return "";
|
||||
var left = ExpressionLambdaToSql(expBinary.Left, _tables, _selectColumnMap, getSelectGroupingMapString, tbtype, isQuoteName, isDisableDiyParse, style);
|
||||
|
@ -335,7 +335,7 @@ namespace FreeSql.MySql {
|
||||
}
|
||||
break;
|
||||
case "Equals": return $"({left} = {getExp(exp.Arguments[0])})";
|
||||
case "CompareTo": return $"(({left}) - ({getExp(exp.Arguments[0])}))";
|
||||
case "CompareTo": return $"timestampdiff(microsecond,{getExp(exp.Arguments[0])},{left})";
|
||||
case "ToString": return $"date_format({left}, '%Y-%m-%d %H:%i:%s.%f')";
|
||||
}
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ namespace FreeSql.SqlServer {
|
||||
}
|
||||
break;
|
||||
case "Equals": return $"({left} = {getExp(exp.Arguments[0])})";
|
||||
case "CompareTo": return $"(({left}) - ({getExp(exp.Arguments[0])}))";
|
||||
case "CompareTo": return $"datediff(second,{getExp(exp.Arguments[0])},{left})";
|
||||
case "ToString": return $"convert(varchar, {left}, 121)";
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user