As far as I'm aware, there isn't a reliable, documented way to get anonymous type properties in the order that they're declared in a source file which causes me to wonder if I use EF core's HasIndex thus:
modelBuilder.Entity<T>(entity => entity.HasIndex(e => new { e.Z, e.A }) )
..is it certain that the index will be created in column order Z,A ?
I'm less concerned about the params string overload form:
modelBuilder.Entity<T>(entity => entity.HasIndex("Z", "A") )
..because I imagine it would be logical for the array element order to dictate the index column order.
I'm struggling to use this form, however, without hardcoded strings because the DbSet<X> is defined thus:
public virtual DbSet<X> X {get;set;}
..rather than the plural Xs (not my rule, but I'm stuck with it), so trying to use HasIndex(nameof(X.Z), nameof(X.A)) is an error because the nearest accessible X is a collection of X, rather than type X, and hence doesn't have the properties I want to nameof
The closest I've been able to come to work around this issue is to instantiate an X:
modelBuilder.Entity<SessionChargingProfileLog>(entity =>
{
var x = new X(0, 0, "");
entity.HasIndex(nameof(x.Z), nameof(x.A)).IsClustered().IncludeProperties(nameof(x.B));
});
..which is a bit..
So if it could be concretely confirmed that "yes, the HasIndex(e => new { e.Z, e.A }) will definitely create the index as Z, A" it'd be be marvellous; I'd test it, but I don't think "try it and observe if it's right in this case" means that it guarantees it will always work out, versus a "yes, it'll work because.."