Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

EFCore indexed column not generated and support for multi column indexing ? #62

Closed
Tristan-gu opened this issue Apr 4, 2019 · 7 comments
Labels
clarification Feature needs clarity to make it more user friendly enhancement New feature request workaround available There's a problem that needs fixed, but a procedure can currently be used to get the same result

Comments

@Tristan-gu
Copy link

Hi,
Waiting for the 2019 relase (#61 ), I'm trying your extension in VS 2017 and your extension is very useful and nice.

But, I think there is a bug in EFCore model: if your set a non Identity column do "indexed", there is absolutely no "hasIndex" generated in the final context.
I don't understand because it's seems to be developed in this source. (line 305).

And, another question, when I saw the code below, I wonder how to generate a multi-column index in EFCore model ? Like this :
modelBuilder.Entity<Item>()HasIndex((Item b) => new { b.column1, b.column2, b.column3 });

Is it planned ?

@msawczyn
Copy link
Owner

msawczyn commented Apr 5, 2019

Multi column indices are supported. That should be in the documentation (if not, I'll make sure it gets added) but I'm not in front of a pc right now so couldn't tell you exactly where to look. I'll try to find that for you shortly.

Index configuration is also available, but to be honest, I've been deep into an ef6 project for quite a while and haven't looked at the efcore T4 for some time. That's about to change. I'll get back to you on this asap.

@Tristan-gu
Copy link
Author

Thanks for your feedback.
I think this exists in EF but not in EFCore.

But I'll wait for your answer.

@msawczyn
Copy link
Owner

We've reworked a lot of things in EFCore for 1.2.7, and have tests validating that multicolumn indexes are good (at least in that version) for EFCore. Can't say they weren't broken in 1.2.6.x ... but the next release is imminent, so this will be fixed.

@msawczyn msawczyn added bug Confirmed bug pending release Issue is resolved in the current codebase, will be published with the next release released Issue is resolved in a current release and removed bug Confirmed bug pending release Issue is resolved in the current codebase, will be published with the next release labels Apr 14, 2019
@msawczyn
Copy link
Owner

1.2.7 pre-release is in the releases. Could you take a peek and see if this resolves your issue? Thanks!

@Tristan-gu
Copy link
Author

I think we don't understand both.
Because my request is to create a new index with columns inside an entity.
An Entity example with these properties:

  • ID
  • PropA
  • PropB
  • PropC

ID is the identity, so, there is a unique index generated automatically.
If I want :

  • a new index 'i1' with PropA and PropB
  • a new index 'i2' with PropA and PropC

How can I do that with your extension ?

@msawczyn
Copy link
Owner

msawczyn commented Apr 17, 2019

Ah, I see what you're after now. You can indeed do what you're asking by implementing the OnModelCreatedImpl partial method in your context class. It's called at the end of OnModelCreating.

void OnModelCreatedImpl(System.Data.Entity.DbModelBuilder modelBuilder) {
   modelBuilder.Entity<Item>().HasIndex((Item b) => new { b.column1, b.column2, b.column3 });
}

Currently, the designer only allows for single column indices, and I can see that this strategy is both unclear and too limiting; you should be able to create multi-column indices, using whatever combination of properties needed. I'm putting that on the list for enhancements.

@msawczyn msawczyn added enhancement New feature request clarification Feature needs clarity to make it more user friendly workaround available There's a problem that needs fixed, but a procedure can currently be used to get the same result and removed released Issue is resolved in a current release labels Apr 17, 2019
@msawczyn msawczyn reopened this Apr 29, 2019
@msawczyn
Copy link
Owner

Deprioritizing this, since indices can be added manually.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
clarification Feature needs clarity to make it more user friendly enhancement New feature request workaround available There's a problem that needs fixed, but a procedure can currently be used to get the same result
Projects
None yet
Development

No branches or pull requests

2 participants