Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Index Expressions #1486

Closed
alc86 opened this issue Sep 2, 2020 · 2 comments
Closed

How to use Index Expressions #1486

alc86 opened this issue Sep 2, 2020 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@alc86
Copy link

alc86 commented Sep 2, 2020

I tried to use the NpgsqlAnnotationNames.IndexExpression but currently this annotation is not supported. Is it possbile to generate the following unique index with standard ef core fluent api:

CREATE UNIQUE INDEX i_nulltest ON "Com_User" (("UserName" IS NULL), ("DeletedDate" IS NULL))
WHERE "UserName" IS NULL OR "DeletedDate" IS NULL;

@roji
Copy link
Member

roji commented Sep 2, 2020

If you're trying to use an index filter (WHERE clause), here are the docs:

modelBuilder.Entity<Blog>().HasIndex(b => b.SomeInt)
    .HasFilter(@"""SomeInt"" IS NOT NULL")
    .IsUnique();

On the other hand, if you're trying to define an expression index, that isn't yet supported by the provider (#119 tracks this). But you can always use raw SQL in migrations to create expression indexes or anything else.

@roji
Copy link
Member

roji commented Sep 2, 2020

Duplicate of #119

@roji roji marked this as a duplicate of #119 Sep 2, 2020
@roji roji closed this as completed Sep 2, 2020
@roji roji added the duplicate This issue or pull request already exists label Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants