编译查询中可以使用 switch 语句吗?
是否可以在 linq toEntity/sql 的编译查询中使用类似 switch 语句之类的东西? 例如,当从数据库返回排序记录时,我想在一个编译查询中使用类似 switch 的语句来对不同属性进行排序,而不必为您可能想要的每个属性编写 2 个编译查询(升序和降序)排序,即使是简单的可排序网格,也最多可以有 10 个已编译的查询。
在 T-SQL 中,使用 case 语句很容易做到这一点,因为我想象大多数数据库都支持这样的构造,那么为什么 linq/entity 框架不支持它呢。
有什么解决办法吗?
Is it at all possible to use something like a switch statement in a compiled query for linq to entities/sql?
For example when returning sorted records from the database, I would like to use a switch-like statement within one compiled query to sort on different properties, instead of having to write 2 compiled queries (ascending & descending) for every property you might want to sort on, which can be up to 10 compiled queries for even a simple sortable grid.
In T-SQL this would be easy with a case statement, as I would imagine a construct like this is supported in most databases, so why would it not be supported in linq/entity framework.
Any solution for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 kyndigs 在他的评论中提到的那样,唯一的解决方案是使用
? 伪造 switch 语句? :
三级运算符:As kyndigs refers to in his comment, the only solution is to fake a switch statement with the
? :
tertiary operator: