Skip to content

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

Closed

Description

@j4587698

问题描述及重现步骤:

使用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

Activity

  1. luoyunchong commented on Jun 18, 2021

    @luoyunchong
    Collaborator

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

  2. added
    bug
    on Jun 18, 2021
  3. luoyunchong commented on Jun 19, 2021

    @luoyunchong
    Collaborator

    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

  4. changed the title [-]DateTime查询问题[/-] [+]Sqlite where.And(x => x.PublishTime.Year == 2021); 查询问题 [/+] on Jun 19, 2021
  5. added a commit that references this issue on Jun 20, 2021
  6. added a commit that references this issue on Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions