0
で.OrderBy()を使うにはどうすればよい私はインターフェイス私が正しく、このシナリオ
public interface IStoreItem
{
decimal Price { get; }
}
そして、それを実装するクラスを持っています。
public class ProductShell : IStoreItem
{
EFDbContext repository = new EFDbContext();
public int ShellID { get; set; }
public bool? Published { get; set; }
public decimal Price { get { return repository.ShellMembers.Where(x => x.ShellID == ShellID).Select(x => x.Product.ListPrice).Sum(); } }
}
価格は、私は、リスト内のすべての変更が表示されないアイテムは、彼らの古い位置に残って、私は(デフォルト)を昇順で[並べ替えを行うことを試みるしかしとき、正しく設定されています。 Priceプロパティが設定されているProductShellオブジェクトは、依然として高い順に並べられています。
List<IStoreItem> StoreItems = new List<IStoreItem>();
StoreItems.AddRange(repository.ProductShells.Where(x => x.Published != null));
StoreItems.OrderBy(x => x.Price);
おかげで...このような何かがまた非常によく動作します:StoreItems = StoreItems.OrderBy(X => x.Price).ToList();私はそのリストにインターフェイスを実装するさまざまな種類のオブジェクトを持っているので、すべてを追加した後にソートする必要があります。 – LaserBeak