title: why does not work OrderBy method in EF core?
body: <p>I want to get sorted products(table products) by 'value'(table Product Parameters) according to "ParamertomId"(table Parameters) from my model.
  How to sort related data correctly?</p>
  
  <p>These are my model classes:</p>
  
  <pre><code>public class Product 
  {
      public int Id { get; set; }
  
      public string Name { get; set; }
      public string Number { get; set; }
      public double Amount { get; set; }
      public double PrimeCostEUR { get; set; }
  
      [ForeignKey("ProductTypeId")]
      public int  ProductTypeId {  get; set; }
      public virtual ProductType ProductType { get; set; }
  
      public ICollection&lt;ProductParameter&gt; ProductParameters { get; set; } = new List&lt;ProductParameter&gt;();
  }
  public class ProductType //: BaseObject
  {   
      public int Id { get; set; }
  
      public string NameType { get; set; }
  
      public ICollection&lt;Parameter&gt; Parameters { get; set; } = new List&lt;Parameter&gt;();
      public ICollection&lt;Product&gt; Products { get; set; } = new List&lt;Product&gt;();
  }
  public class Parameter 
  {
      public int Id { get; set; }
      public string Name { get; set; }
  
      [ForeignKey("ProductType")]
      public int ProductTypeId { get; set; }
      public  virtual ProductType ProductType { get; set; }
  
      public ICollection&lt;ProductParameter&gt; ProductParameters { get; set; } = new List&lt;ProductParameter&gt;();
  }
   public class ProductParameter 
  {
      public int Id { get; set; }
  
      public int ProductId { get; set; }
      public virtual Product Product { get; set; }
  
      public int ParameterId { get; set; }
      public virtual Parameter Parameter { get; set; }
  
      public string Value { get; set; }
  
  }
  </code></pre>
  
  <p>These are my DTO classes needed to display the data I need.:</p>
  
  <pre><code>public class ProductDTO{   
     public int ProductId { get; set; }
     public string Number { get; set; }
     public double Amount { get; set; }
     public double PrimeCostEUR { get; set; }
  
     public int ProductTypeId { get; set; }
     public string NameType { get; set; }
  
     public ICollection&lt;ParameterDTO&gt; Parameters { get; set; } = new 
     List&lt;ParameterDTO&gt;();}
  
  public class ParameterDTO {
     public int Id { get; set; }
     public string Name { get; set; }
     public string Value { get; set; }
  }
  </code></pre>
  
  <p>I receive related data from three table. This my method GetSortedProducts:</p>
  
  <pre><code>public async Task&lt;IEnumerable&lt;ProductDTO&gt;&gt; GetProducts(int id)
  {
      var typeParams = _context.Parameters
          .Where(t =&gt; t.ProductTypeId == id)
          .ToList();
  
      var products =  _context.Products
          .Include(t =&gt; t.ProductParameters)
          .Where(t =&gt; t.ProductTypeId == id)
          .ToList();
  
      var items = new List&lt;ProductDTO&gt;();
  
      foreach (var product in products)
      {
          var productDTO = new ProductDTO()
          {
              ProductId = product.Id,
              Number = product.Number,
              Amount = product.Amount,
              PrimeCostEUR = product.PrimeCostEUR,
              ProductTypeId = product.ProductTypeId
          };
  
          foreach (var typeParam in typeParams)
          {
              var paramDTO = new ParameterDTO();                        
              var value = product.ProductParameters.FirstOrDefault(t =&gt; t.ParameterId == typeParam.Id);
              if (value != null)
              {
                  paramDTO.Id = value.Id;
                  paramDTO.Value = value.Value;
              }
              paramDTO.ParameterId = typeParam.Id;
              paramDTO.Name = typeParam.Name;
  
              productDTO.Parameters.Add(paramDTO);
          }
            // sort products by value
           productDTO.Parameters.Where(y =&gt; y.ParameterId == 4)
           .OrderBy(t =&gt; t.Value).ToList();
  
           items.Add(productDTO);
      }        
  
      return items;           
  }
  </code></pre>