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

Skip index and FK creation using fluent API builder #35066

Open
amyboose opened this issue Nov 9, 2024 · 1 comment
Open

Skip index and FK creation using fluent API builder #35066

amyboose opened this issue Nov 9, 2024 · 1 comment

Comments

@amyboose
Copy link

amyboose commented Nov 9, 2024

What problem are you trying to solve?

I want to suggest one additional option to conditionally remove index creation.
There is a solution to conditionally remove indexes using convention.

But it is better to understand when model building and index creation located in one single place. For example, I configure model using IEntityTypeConfigaration and this is the only one place where every model is configured.

Describe the solution you'd like

It can looks like this:

// first option
builder
    .HasOne(x => x.Product)
    .WithMany()
    .HasNoIndex();

// second option
builder
    .HasNoIndex(x => new { x.UserId, x.ProductId });

Also there is an extension for Postgresql "TimescalDb" and sometimes it doesn't allow to create foreign keys for time-series tables.
It can be useful to have API to skip creation foreign keys.

It can looks like this:

builder
    .HasOne(x => x.Product)
    .WithMany()
    .HasForeignKey(x => x.ProductId, createInDatabase: false);
@amyboose amyboose changed the title Skip index and FK cretion using fluent API builder Skip index and FK creation using fluent API builder Nov 9, 2024
@roji
Copy link
Member

roji commented Nov 12, 2024

Not creating foreign keys in the database is tracked by #15854, you can follow that to be informed of progress.

Regarding not creating indexes... If you'd like to systematically stop creating indexes for foreign keys, that's something that generally belongs in a convention (like the one you linked to) - you should not be manually doing this for every index manually.

Otherwise, if you're really looking to selectively remove a specific index that's been configured by convention, @AndriySvyryd probably has the right answer (the metadata APIs can be used to manipulate indexes directly, but foreign key indexes are added only later...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants