c# - MVC Core 2 - lambda 表达式中的 && 运算符不起作用
问题描述
Visual Studio - 使用 Microsoft ASP.NET 控制器的 MVC Core2
我正在尝试根据用户过滤记录,如果它被标记为删除(布尔数据类型)
我正在使用 && 运算符并尝试按日期列排序,但是它不起作用
这是我的代码
var DataContext = _context.Shops_Basket.Include(c => c.products)
.Where(c => c.Username == user && c.IsDeleted == 0)).Orderby dates desc;
解决方案
Orderby dates desc
不是有效的 C#。可能您对 SQL 感到困惑。您需要使用OrderByDescending
:
var dataContext = _context.Shops_Basket.Include(c => c.products)
.Where(c => c.Username == user && c.IsDeleted == 0)
.OrderByDescending(c => c.dates);
另请注意,我们在 C# 中有命名约定。局部变量以较低的字符开头。Shops_Basket
我们通常不使用下划线。取而代之的是更好的DbSet
名字ShopsBasket
。
推荐阅读
- docker - docker:创建 daemon.json 后 docker start 失败
- reactjs - React - 使用 Superagent 等待请求结束
- javascript - 展开/折叠表格数据
- javascript - 无法更改 Office UI React Dialog 版本的样式。5.56.0
- java - 在 android 中读取公共共享谷歌驱动器中的内容
- javafx - 如何正确构建 JavaFX 可样式化对象,可以是 GC
- java - 如何在okhttp中为拦截器设置延迟?
- c# - 清除 CollectionViewSource 的源时,WPF 接口变得无响应
- qgis - 从 QGIS 发布编辑到 Open Street Map 数据库
- swift - Swift init() 可以返回以前创建的对象吗?