title: Sorting navigation properties in Entity Framework
body: <p>Consider the following database tables:</p>
  
  <pre><code>CREATE TABLE [dbo].[Step]
  (
     [StepId] INT NOT NULL PRIMARY KEY IDENTITY,
     [OrderIndex] INT NOT NULL
  )
  
  CREATE TABLE [dbo].[StepInput]
  (
     [StepInputId] INT NOT NULL PRIMARY KEY IDENTITY, 
     [StepId] INT NOT NULL, 
     [OrderIndex] INT NOT NULL, 
     CONSTRAINT [FK_StepInput_Step] FOREIGN KEY ([StepId]) REFERENCES [Step]([StepId])  ON DELETE CASCADE, 
  )
  </code></pre>
  
  <p>With the following POCOs:</p>
  
  <pre><code>public class Step
  {
     public virtual int StepId { get; set; }
     public virtual ICollection&lt;StepInput&gt; StepInputs { get; set; }
  }
  
  public class StepInput
  {
     public int StepInputId { get; set; }
     public int StepId { get; set; }
     public virtual int OrderIndex { get; set; }
  }
  </code></pre>
  
  <p>I would like for StepInputs to be ordered by OrderIndex. Is there any way to setup the navigation property so that it is sorted automatically by EF, so that the user of Step does not have to call StepInputs.OrderBy every time?</p>
  
  <p>I am using the database-first model.</p>
  
  <p>Edit: I did realize that I could just add an OrderedInputs property to Step, which returns StepInputs.OrderBy(...), which solved the immediate problem, though I'm not sure about the performance implications. I am still curious as to whether there is a way to set this up in EF without having to use a custom property.</p>