msawczyn/EFDesigner

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

Tristan-gu opened this issue · 7 comments

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 ?

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.

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

But I'll wait for your answer.

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.

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

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 ?

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.

Deprioritizing this, since indices can be added manually.