C# .NET EF core 多表联合 多条件 null值 模糊查询

今天遇到多表联合模糊查询的功能 遇到多个多表联合多条件模糊查询 的功能实现

记录一下

 

 //获取总记录数
                var totalRows = (from c in _dbContext.ChildOrders
                                 join o in _dbContext.Orders on c.OrderId equals o.Id
                                 join p in _dbContext.Platforms on o.PlatformId equals p.Id
                                 where (c.Deleted == false && c.Disable == false && o.Deleted == false && o.Disabled == false && o.Uid == int.Parse(HttpContext.User.Identity.Name)
                                 && (string.IsNullOrEmpty(CID.ToString()) ? true : c.Id.Equals(CID))
                                 && (string.IsNullOrEmpty(PlatformId.ToString()) ? true : o.PlatformId.Equals(PlatformId))
                                 && (string.IsNullOrEmpty(school) ? true : o.School.Contains(school))
                                 && (string.IsNullOrEmpty(username) ? true : o.UserName.Contains(username))
                                 && (string.IsNullOrEmpty(className) ? true : c.Name.Contains(className))
                                 && (string.IsNullOrEmpty(runstatus.ToString()) ? true : c.RunStatus.Equals(runstatus))
                                 )
                                 select c).Count();

  主要用了三目运算符 过滤掉null值条件  否则搜索不到数据

posted @ 2022-06-13 00:17  Echo_xxx  阅读(1984)  评论(0编辑  收藏  举报