I am trying to create a unique index with multiple columns using the shadow property. I know that I can solve this problem by simply adding a property, but I would like to see if this is possible if not to make it so that my model is clean.
To create a multi-column index, you have the following parameter in the Fluent API:
modelBuilder.Entity<AlbumTrack>().HasIndex(t => new { t.TrackNumber, t.AlbumId).IsUnique();
But I donβt want to clutter up my model with the additional AlbumId property and, therefore, I want to use the shadow property, for one column this works:
modelBuilder.Entity<AlbumTrack>().HasIndex(t => EF.Property<int>(t,"AlbumId")).IsUnique();
But for an index with multiple columns using the shadow property, like the following
modelBuilder.Entity<AlbumTrack>()
.HasIndex(t => new { t.TrackNumber, EF.Property<int>(t,"AlbumId")})
.IsUnique();
I get the following error in vscode
. , .
- , ?