This commit is contained in:
skx 2020-11-10 18:38:45 +08:00
parent f91038adb2
commit 15573551bf
2 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace OrmTest.Test
{
public class BugTest1
{
public static void Init()
{
SqlSugarClient db = new SqlSugarClient(
new ConnectionConfig()
{
ConnectionString = Config.ConnectionString,
DbType = DbType.MySql,//设置数据库类型
IsAutoCloseConnection = true,//自动释放数据务,如果存在事务,在事务结束后释放
InitKeyType = InitKeyType.Attribute //从实体特性中读取主键自增列信息
});
db.Aop.OnError = (exp) =>//SQL报错
{
string sql = exp.Sql;
//exp.sql 这样可以拿到错误SQL
};
//db.DbMaintenance.CreateDatabase();
db.Deleteable<Order>().ExecuteCommand();
db.Insertable(new Order() { CreateTime = DateTime.Now.Date.AddDays(-1), Name = "1a", Price = 1, CustomId = 1 }).ExecuteCommand();
db.Insertable(new Order() { CreateTime = DateTime.Now.Date.AddDays(-1).AddHours(23), Name = "1a", Price = 1, CustomId = 1 }).ExecuteCommand();
db.Insertable(new Order() { CreateTime = DateTime.Now.Date.AddDays(1), Name = "1a", Price = 1, CustomId = 1 }).ExecuteCommand();
db.Insertable(new Order() { CreateTime = DateTime.Now.Date.AddDays(2), Name = "1a", Price = 1, CustomId = 1 }).ExecuteCommand();
var s =DateTime.Now.Date.AddMilliseconds(-1);
var list= db.Queryable<Order>().Where(it => SqlFunc.DateIsSame(it.CreateTime,s)).ToList();
var s2 = DateTime.Now.Date.AddDays(-1);
var lists = db.Queryable<Order>().Where(it => SqlFunc.DateIsSame(it.CreateTime, s2)).ToSql();
Console.ReadKey();
}
}
}

View File

@ -50,6 +50,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="Bugs\BugTest1.cs" />
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
<Compile Include="Demo\Demo1_Queryable.cs" />
<Compile Include="Demo\Demo2_Updateable.cs" />