-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Upgrade to EFCore 7 Results in Unexpected Index Changes #29847
Comments
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate. |
Thank you for your reply @ajcvickers unfortunately I am not sure that is viable due to the size of my model. That is, I am not even sure where I would begin with such an effort. This same model worked fine in EFCore6 and I am attempting to upgrade to EFCore7 but running into this issue. |
@Mike-E-angelo The problem is that if you can't reproduce it in a way we can investigate with all the code available to you and good knowledge of how it works, then the chances we can do so without these things is practically nil. |
I don't know if this it same issue, but I have a project running EF Core 6, that after upgrade to EF Core 7.0 fails with: System.InvalidOperationException: 'The property 'IncomingInvoice' cannot be removed from entity type 'IncomingInvoiceResent' because it is being used in the index {'IncomingInvoice'} on 'IncomingInvoiceResent'. All containing indexes must be removed or redefined before the property can be removed.' running this line: Basically the model has a 1:1 relationship that seems EF Core 7.0 is trying to remove. Any idea? |
After some thought @ajcvickers I do have a previous older version of my solution that I have provided for developercommunity issues in the past. I upgraded it to You can find this here: It's not exactly simple, but it allows you to see the issue that is preventing me from upgrading to EfCore7. I am hoping you are able to work with it. 🙏 |
@Mike-E-angelo So now I have your code. What are the exact steps I should follow to reproduce the issue? |
Thank you for your reply and investigation @ajcvickers ... I did provide the steps in the reported issue. Here they are for your review:
|
The solution doesn't load for me. I get 154 NuGet errors. |
To be certain @ajcvickers I am using Developer PowerShell in my Visual Studio instance, but that is not necessary. As denoted in the original ticket description above the problem occurs when running a How do you usually run This is what I see when unzipping the provided zip file, and following the directions on my local machine: |
In order to investigate I need to be able to build the application. How do I do that? |
I was under the impression |
@Mike-E-angelo I need a solution that I can open in Visual Studio (or some other IDE) and work with. Otherwise how am I to debug, rip out code and re-build, and all the other things associated with root-causing an issue? |
@ajcvickers pardon my confusion here but are you saying that the |
Incidentally @ajcvickers this same solution was successfully loaded and built in another issue so whatever you are experiencing here seems to be localized to your environment. 🤔 |
Hi @ajcvickers I wanted to check in on this issue as I have not heard back from you, and I want to be sure that you are not blocked on anything from my side. It is still unclear to me what the issue is (if any) that is blocking you, as very few details have been provided to me. Please note that based on this issue there have now been two other Microsoft employees that have managed to use the same .zip file, to unzip and successfully build the provided solution without any assistance or direction from me. As an option, we can ping them to see if they can assist you with your environment there. Thank you for any update you can provide. 👍🙏 |
@Mike-E-angelo My next steps on this are:
These things are usually done by the person filing the issue, since, as noted above, they presumably already have a solution that builds and also know the code and hence do not have to spend time understanding what is happening in parts of the code unrelated to the issue or EF Core. However, since you are unable to do this, I will make an attempt. That being said, I am prioritizing other work ahead of it at the moment, since the amount of work is high compared to investigating other issues, and yet the resulting value is unchanged. |
There seems to be some continuing confusion here @ajcvickers, please do pardon it from my side. It is my impression and understanding that running Here is what I see, noting the For clarity and your convenience, this is the command as originally reported in this ticket from over a week ago as well as the developercommunity ticket where the zip was provided:
As I mentioned and demonstrated here, I am able to build the solution fine on my side, and as I have mentioned with the other developercommunity issue, it builds fine with two other machines there. Additionally, I asked here if you are able to run the command to build the solution but did not hear back from you.
For further clarity from my side as I understand it, the amount of work here is to run a |
@Mike-E-angelo This was my original request, which is the same request made to anyone submitting an issue with insufficient information for us to move forward:
You have not done this. Providing access to your entire solution is not this. Even if I can reproduce the issue on the command line with the code you provided, that still doesn't get me close to a "small, runnable project." If you are able to do make such a project, then please do so. If you are not able, then I will attempt it, but this requires I have your code in a state that builds in an IDE, which it currently does not for me. Maybe that's due to my machine, maybe not. Either way, I have to take time to make it build, and only then can I start trimming it down to the small project that is needed to understand what is really going on and move forward. So, again, the bottom line is can you, like everyone else, "attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate?" If yes, then this issue comes into line with all the other bugs filed. If not, then I'll spend some time to try to get there, but it is considerable more work on our side, which changes the cost/value ratio. |
This was not clear to me until now, as this was never stated. Thank you for verifying. The only reference I have is this comment and this comment, both which imply that there is a problem with building the solution. It is my understanding that if
As I mentioned here no this is not feasible with my current environment+situation, along with acknowledging that the provided solution is not simple, but does demonstrate how I and others are currently not able to migrate to EfCore7 due to this issue. |
FWIW @ajcvickers I have attached a zip file with much fewer projects, down to only 8 from the 100+ as provided earlier. It can be found at this comment/reaction here: Please note that the original zip that I had provided earlier has been used to track down several issues in both Microsoft and JetBrains this year, so it was a go-to solution when I thought of it here. Based on that conditioning, it did not strike me that I could reduce the number of projects until today (and thinking of the discussion here). Note that I was able to run the following commands in the unzipped directory and got the error to surface:
Additionally, I was able to subsequently open the I am hoping the smaller solution will assist you here. Please let me know if there is any further information I can provide to further assist you in this matter. |
@Mike-E-angelo The [Index(nameof(Subject), IsUnique = true)]
public class DepositOrder : ExternalProcess
{
public Checkout Subject { get; set; } = default!;
public Deposit? Result { get; set; }
} But then @AndriySvyryd We might want to throw a better exception or do something in model validation. Minimal repro: [Index(nameof(Subject), IsUnique = true)]
public class DepositOrder
{
public Guid Id { get; set; }
public Checkout Subject { get; set; } = default!;
}
public class Checkout
{
public DateTimeOffset Created { get; set; }
}
public class SomeDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(@"Data Source=(LocalDb)\MSSQLLocalDB;Database=AllTogetherNow")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<DepositOrder>().OwnsOne(e => e.Subject);
}
}
public class Program
{
public static async Task Main()
{
using (var context = new SomeDbContext())
{
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
}
}
} |
Thank you very much for your time and investigation @ajcvickers it is appreciated. 🙏
Can you please go into more detail about this? This is what I see for my configuration and it does not make use of the Additionally, I am curious about why this works in EFCore6 but not EFCore7. Thank you for any continued time/insight you can provide. |
@Mike-E-angelo You're right, it's not
The model is not valid in either case. The |
OK sounds good to me, @ajcvickers. Thank you again for your time and patience. That does solve one problem but there is another problem as mentioned in the original issue that an index gets re-created with what appears to be the wrong filter:
Shouldn't this be Unfortunately, I tried to reproduce this in the solution we're using here but this column does not exist there. I will see about getting something for you to test now that I am unblocked with this first issue. |
EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it. BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions. |
File a bug
Remember:
I did a search for the following:
All containing indexes must be removed or redefined before the property can be removed.
and this did not return anything so I am filing a new issue here to investigate.Additionally, I also did a search for "index" on this document:
https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-7.0/breaking-changes
And it does not surface anything obvious to the issue that I am experiencing.
I have attempted to upgrade my model to EfCore 7, using the following command:
This results in the following error:
Include your code
Ok, so it seems like I need to create a migration to do this? I attempt to do so.
My class looks like this:
So I comment out the
[Index(nameof(Subject), IsUnique = true)]
. This occurs for other 3 classes throwing this error and after commenting out the indexes I finally get a migration created.(Note that zero model changes with the exception of the above have been done for my model and worked fantastic in EFCore6)
Within the migration, several indexes + FKs are dropped and recreated -- none of which are related to the classes with indexes I commented above. Here is an example
Note that
filter: "[SourceId] IS NOT NULL"
... shouldn't this befilter: "[SystemDebit_SourceId] IS NOT NULL"
?Include stack traces
NA this is upgrading from EFCore6 -> 7.
Include verbose output
As this output exposes a good deal of my model I am not comfortable posting this here, but can do so by request to a secure location if necessary. 👍
Include provider and version information
EF Core version: 7
Database provider: . Microsoft.EntityFrameworkCore.SqlServer
Target framework: (e.g. .NET 7.0)
Operating system: Windows 10
IDE: Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.5.0 Preview 1.0
The text was updated successfully, but these errors were encountered: