-
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
Scaffolded database fails OnModelCreating when table has index with included columns snake_case named #23068
Comments
Have you tried -UseDatabaseNames option? |
Thank you @ErikEJ scaffolding with UseDatabaseNames will make dbcontext that hasn't got a problem with indexes that include colons with snake_case names but using this option makes every entity and property have an ugly snake case name. I already scaffolded the database with these indexes before .Net5 RC2. Here is spinet from my db context scaffolded before and after (.Net5 RC2 and power-eftools).
After (faling):
|
Duplicate of #22150 |
@adopilot pluralization is enabled by default with EF Core 5 (breaking change) You can disable with the -NoPluralize option |
DbContex created scaffolding from existing database fails on method OnModelCreating in runtime if in database has tables with indexed which using columns named snake_cased.
Here is steps.
In sql create table with index
Then in Visual studio in Pacgae Manager Console
Scaffold-DbContext "data source=.;initial catalog=Test;persist security info=True;user id=xx;password=xxx;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Data\Test -f
This will generate DbContext.
App with this DbContext will build and run, but at first call to database OnModelCreating
e.g:
var test= await _testContext.TableTests.ToListAsync();
App will fall into exception
Include property 'TableTest.col_date' not found.
Investigating OnModelCreating I fund that these lines cause exception
My test table is scaffolded like this:
Annoying thing is that this happening in runtime after app is started, and exception message is so unclear to find what is wrong.
If you have large set of index like this in db you have to run over and over to find all wrong indexes, and comment them.
If we could change the column names then we would not use the db-first approach
EF Core version: 5.0.0-rc.2.20475.6
Microsoft.EntityFrameworkCore.Tools :5.0.0-rc.2.20475.6
Target framework: .NET 5.0 RC2
Operating system: Windows 10 x64
SQL Server version: Microsoft SQL Server 2012 (SP3-GDR) (KB4019092) - 11.0.6251.0 (X64)
IDE: Visual Studio 2019 16.8.0 Preview 5.0
The text was updated successfully, but these errors were encountered: