C# 在EntityFramework中按列表项排序项目
我有一个有价目表的产品,我可以按价格订购吗C# 在EntityFramework中按列表项排序项目,c#,entity-framework,lambda,C#,Entity Framework,Lambda,我有一个有价目表的产品,我可以按价格订购吗 public class Product { public int Id { get; set; } public string Title { get; set; } public IList<ProductPrice> ProductPrices{ get; set; } } public class ProductPrice { public int Id { get; set; } publi
public class Product
{
public int Id { get; set; }
public string Title { get; set; }
public IList<ProductPrice> ProductPrices{ get; set; }
}
public class ProductPrice
{
public int Id { get; set; }
public int Degree{ get; set; }
public int Price{ get; set; }
}
您不需要
选择
,只需直接调用OrderBy
和Max
var listSorted = _db.Products.OrderBy(p => p.ProductPrices.Max(pp => pp.Price))
您不需要
选择
,只需直接调用OrderBy
和Max
var listSorted = _db.Products.OrderBy(p => p.ProductPrices.Max(pp => pp.Price))
如果您想以最高产品价格订购产品,请执行以下操作:
_db.Products.OrderBy(p => p.ProductPrices.Max(pp => pp.Price))
如果您想以最高产品价格订购产品,请执行以下操作:
_db.Products.OrderBy(p => p.ProductPrices.Max(pp => pp.Price))
那么,当一个产品有多个价格时,您希望按哪个价格排序?您希望订购什么?按每种产品的最低价格订购的产品,或按任何顺序订购的产品,每种产品的价格按升序排列?(如果你有
{title:apple,prices:[0.12,0.09]},{title:banana,prices:[0.08,0.09]}
你想要{title:apple,prices:[0.09,0.12]},{title:banana,prices:[0.08,0.09]}还是想要{title:apple,prices:[0.12,0.09]}
(或者你想同时进行价格排序,然后再按第一个价格进行产品排序?{title:banana,价格:[0.08,0.09]},{title:apple,价格:[0.09,0.12]}
我想对价格最高的产品进行排序。例如{title:apple,价格:[0.09,0.12]},{title:banana prices,价格:[0.08,0.09]}
和最低价格{title:banana,prices:[0.08,0.09]},{title:apple,prices:[0.12,0.09]}
那么当一个产品有多个时,你想按哪个价格排序?你想订购什么?按每个产品的最低价格订购的产品,或者按任何顺序订购的产品,每个产品的价格按升序排列?(如果你有{title:apple,prices:[0.12,0.09]},{title:banana,prices:[0.08,0.09]}
你想要{title:apple,prices:[0.09,0.12]},{title:banana,prices:[0.08,0.09]}
还是想要{title:banana,prices:[0.12,0.09]}
(或者你想要价格排序,然后按照第一个价格排序?{title:panana,prices:[0.08,0.09]},{title:apple,prices:[0.09,0.12]}
我想对价格最高的产品进行排序。例如,{code>{title:apple,prices:[0.09,0.12]},{title:panana,prices:[0.08,0.09]}和最低价格{title:panana,prices 0.08,0.09]},{title:apple,prices
谢谢,但我想用最高价格对产品项目进行排序。@andyb952是的,我想是的,但您有其他解决方案吗?此订单为productprice,但我想订购ProductsHanks,但我想用最高价格对产品项目进行排序。@andyb952是的,我想是的,但您有其他解决方案吗?此订单为productprice,但我想订购产品