title: Preserve Oder of Entity References Collection in EF Core 5
body: <p>I have to preserve the order of a list of entity references. I tried a lot, but nothing really works so far. Example:</p>
  <pre><code>public class Module 
  {
      public long RowId { get; set; }
  }
  
  public class Engine 
  {
      public long RowId { get; set; }
      public IList&lt;Module&gt; Modules { get; set; }
  }
  
  public class EngineModule 
  {
      public long Ordinal { get; set; }
      public Module Module { get; set; }
  }
  
  public class MyDbContext : DbContext 
  {
      public DbSet&lt;Module&gt; Modules { get; set; }
      public DbSet&lt;Engine&gt; Engines { get; set; }
  
      protected override void OnModelCreating(ModelBuilder modelBuilder) 
      {
          modelBuilder.Entity&lt;Module&gt;(e =&gt; {
              e.HasKey(p =&gt; p.RowId);
          });
  
          modelBuilder.Entity&lt;Engine&gt;(e =&gt; {
              e.HasKey(p =&gt; p.RowId);
              e.Property(p =&gt; p.Modules).HasConversion(
                  l =&gt; l == null ? null : Enumerable.Range(0, l.Count).Select(i =&gt; new EngineModule { Ordinal = i, Module = l[i] }).ToList(),
                  l =&gt; l == null ? null : l.OrderBy(c =&gt; c.Ordinal).Select(c =&gt; c.Module).ToList()
              );
          });
      }
  }
  </code></pre>
  <p>In this case I get an exception stating, the database provider does not support CLR-Type EngineModule.</p>
  <p>What would be the easiest way to achieve my goal in EF Core 5?</p>