-
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
EF Core 6.0 regression when using HasDefaultSchema() with ToTable(null) #26651
Comments
FYI for those impacted by this issue: EF Core 6.0.1 is now available from NuGet. |
Still happens in EF Core 7.0.1.0.
as result of this, views of schema "Y" in snapshot are configured as:
|
@psp-glt Please open a new issue and attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate. |
We are getting this issue, as described by @psp-glt , as well in v8.0.0
|
Hey, I'm in the middle of upgrading my application from EF Core 5.0 to EF Core 6.0. I've observed a regression that to the best of my knowledge looks like a bug in EF Core 6.0.
In EF Core 5.0 I have a context with following model creation:
ToTable(null)
became ambiguous in EF Core 6.0, so I fixed it according to the docs:As a side note, I had to fix all of my past migrations and the model snapshot itself from
b.ToTable(null);
tob.ToTable((string) null);
, this is alright. Everything seems fine after those fixes, code compiles, no errors for now.The problem however happens when running
dotnet ef
tool in order to e.g. generate new migration, which refreshes the context snapshot model. It changes my previously-fixed this line:Into this:
This in result causes an exception when generating a migration script:
This is because it no longer executes this function:
But this one:
Where
name
is marked as non-null, and in fact, checked in a safeguard when calling the function.If you asked me about this, the model -> snapshot generation code should not include default schema name when
name
isnull
, generatingb.ToTable(null);
like before, now corrected tob.ToTable((string)null);
. Alternatively, you should allow thestring name, string? schema
declaration to allowstring? name
and not throw on it beingnull
, which is a valid use case when the user doesn't want any table generated for given entity. I believe the first option is more appropriate, but I'm not an expert in EF internals so do whatever you consider best, that's only my thoughts in regards to this issue.As a workaround, I've removed
modelBuilder.HasDefaultSchema("example");
which changedb.ToTable((string)null, "example");
intob.ToTable((string)null);
, fixing my problem. Obviously this is not the correct solution, as I'd want to have given schema name by default. I didn't find any way to somehow rewrite myToTable
call inOnModelCreating()
to solve this issue, no signature allows me to emit no table and skip the default schema name being used in a model, I've tried several - let me know if I missed anything.Thank you in advance for taking your time to look into this bug report. Let me know if by any chance you need more information and I'll try to provide as much as needed to tackle this one down.
The text was updated successfully, but these errors were encountered: