Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite where.And(x => x.PublishTime.Year == 2021); 查询问题 #804

Closed
j4587698 opened this issue Jun 18, 2021 · 2 comments
Closed

Sqlite where.And(x => x.PublishTime.Year == 2021); 查询问题 #804

j4587698 opened this issue Jun 18, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@j4587698
Copy link

问题描述及重现步骤:

使用DateTime.Year进行查询,代码类似
where.And(x => x.PublishTime.Year == 2021);

在Sqlite数据库中,x.PublishTime.Year == 2021会转换成strftime('%Y',a."PublishTime") = 2021,前面为char类型,后面是int类型,无法查询到正确的数据。
如果使用
where.And(x => x.PublishTime.Year.ToString() == "2021");
会转换为cast(strftime('%Y',a."PublishTime") as character) = '2021',也无法查询到正确数据。

应该转换为strftime('%Y',a."PublishTime") = '2021',即前后都为char,在c#中表示应该类似为
where.And(x => x.PublishTime.Year == "2021");
但是由于数据类型不一致,无法编译通过。

数据库的具体版本

Sqlite

安装的包

FreeSql.All 2.5.100

.net framework/. net core? 及具体版本

.Net5

@luoyunchong
Copy link
Collaborator

where.And(x => x.PublishTime.Year.ToString() == "2021"); 测试 没问题。

@luoyunchong luoyunchong added the bug Something isn't working label Jun 18, 2021
@luoyunchong
Copy link
Collaborator

luoyunchong commented Jun 19, 2021

sqlite strftime('%m',a."CreateTime") 查出来的数据 是06 而不是 6 。

Millisecond 没有*1000,得到0
Ticks 精度有些问题。

所以这个时间处理上还是有问题。

 var d3 = fsql.Select<Users>().ToList(r=>new { 
                r.CreateTime,
                r.CreateTime.Date,
                r.CreateTime.TimeOfDay,
                r.CreateTime.DayOfWeek,
                r.CreateTime.Day,
                r.CreateTime.DayOfYear,
                r.CreateTime.Month,
                r.CreateTime.Year,
                r.CreateTime.Hour,
                r.CreateTime.Minute,
                r.CreateTime.Second,
                r.CreateTime.Millisecond,
                r.CreateTime.Ticks,
            });

image

@luoyunchong luoyunchong changed the title DateTime查询问题 Sqlite where.And(x => x.PublishTime.Year == 2021); 查询问题 Jun 19, 2021
2881099 added a commit that referenced this issue Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants