gpt4 book ai didi

c# - 按定制订单订购商品

转载 作者:行者123 更新时间:2023-12-02 19:41:57 24 4
gpt4 key购买 nike

我有一个插入数据库的列表:

List<House> houses = new List<House> {
new House { Id = 1, Type = "A" },
new House { Id = 2, Type = "B" },
new House { Id = 3, Type = "C" }
new House { Id = 4, Type = "B" }
}

使用 Linq to Entities 我需要按类型排序房屋,但它应该是:

 Houses of Type C
Houses of Type A
Houses of Type B

如何做到这一点?

最佳答案

你可以链接吗? : 操作符创建一个自定义排序,如下所示:

var query = from h in context.Houses
orderby h.Type == "C" ? 0 : (h.Type == "A" ? 1 : 2)
select h;

或者方法语法

var query = context.Houses.OrderBy(h => h.Type == "C" ? 0 : (h.Type == "A" ? 1 : 2))

关于c# - 按定制订单订购商品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59935634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com