efcore icon indicating copy to clipboard operation
efcore copied to clipboard

The Cosmos provider ignores configured indexes

Open ajcvickers opened this issue 1 year ago • 3 comments

For example:

modelBuilder.Entity<Book>().HasIndex(e => e.ByteArray);

This will currently pass model validation, but the index is ignored. We should fail for this in model validation.

ajcvickers avatar Jun 18 '24 13:06 ajcvickers

Or implement it ;)

roji avatar Jun 18 '24 13:06 roji

Or implement it ;)

I could be wrong, but I don't think a naked .HasIndex call will ever do anything on Cosmos. You're going to need to chain something (like ForVectors) to specify how it will be used in the index specification.

ajcvickers avatar Jun 18 '24 13:06 ajcvickers

This definitely would require more thinking... You know more than me, but it seems like it could make sense to apply a Cosmos indexing policy that includes paths only to the properties on which HasIndex() has been called, no? One big difference from relational is that in relational, there are no indexes by default, whereas in Cosmos everything seems to be indexed by default, and the policy is more of a way to do finer-grained tweaking to only index specific properties.

In any case, probably not for 9.0, so yeah, validating against HasIndex() at this point sounds like the right thing indeed...

roji avatar Jun 19 '24 14:06 roji

See #32517 for enabling proper support for HasIndex() on Cosmos.

roji avatar Sep 22 '24 11:09 roji

This has caused an unforeseen problem with by project. See #35264 Instead of throw an exception, how about throw a warning?

toiyabe avatar Dec 03 '24 17:12 toiyabe

Another use-case for being able to include HasIndex would be in situations/applications where you want to allow the person installing your software to choose which database provider they wish to use.

Since EF Core supports SQL and NoSQL databases now, including CosmosDB it would make sense to ensure that developers can use all of the features & functionality of EF Core in their apps without restricting it with exceptions and other errors/warnings based on the specific provider.

My end customer should be able to install my software and select SQL Server, Postgres or Cosmos and EF Core should be able to handle it (as long as I don't do any direct usage of the database/SQL myself).

hades200082 avatar Dec 19 '24 14:12 hades200082