System.InvalidOperationException: The binary operator NotEqual is not defined for the types 'Microsoft.EntityFrameworkCore.Storage.ValueBuffer' and 'Microsoft.EntityFrameworkCore.Storage.ValueBuffer'.

  .netcore 2.1使用左表连接时报错,原因是对数据库中实体 DateTimeOffset date做查询判断时,将数据库中date转为string进行了判断,这样判断是错误的,并且效率低,应该是不改变数据库中字段类型,将查询条件字段更改为数据库字段类型

  错误的写法:

 var _upTwoLst = _postgreDbContext.income.Where(m=>m.date.Date.ToString("yyyy-MM-dd") == DateTimeOffset.Now.AddDays(-1).ToString("yyyy-MM-dd"));

  正确的写法:

 var _upTwoLst = _postgreDbContext.income.Where(m=>m.date== DateTimeOffset.Parse(DateTimeOffset.Now.AddDays(-2).ToString("yyyy-MM-dd")));

 

posted @ 2019-10-28 16:51  低调码农哥!  阅读(1358)  评论(0编辑  收藏  举报