I want to understand how can data be retrieved efficiently in EF Core if I have defined a secondary index (non-clustered) for my table.
I want to be able to do efficient lookups of single elements based on the secondary index:
public class Entity
{
[Key]
public long Id{get;set;}
[Index(IsClustered=false,IsUnique=false)]
public string SecondaryId{get;set;}
}
public class MyContext:DbContext{
public DbSet<Entity> Entities{get;set;}
}
public void Find(long primaryIndex,string SecondaryId,MyContext context)
{
var normalSearch=context.Entities.Find(primaryIndex);
var secondaryIndexSearch=context.Entites.Find(SecondaryId); //does it know to look at the `SecondaryId` column and detect that its a secondary index ?
}