-
Notifications
You must be signed in to change notification settings - Fork 230
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
dotnet-ef 6.0.1 scaffold ignores table with many to may relation #2239
Comments
This is by-design: EF Core 6.0 detects simple many-to-many join tables in the database, and does not scaffold an entity for them. If you create a database from that scaffolded model, you'll see the Artomadu being created. If you need to include it explicitly in a query, you can also do that; see the EF docs for more information. |
I need update, insert and delete Artomadu table like other tables.
causes Artomadu class to be generated like for other tables. |
Yes - this is once again by design - see dotnet/efcore#22475. When EF Core detects a simple join pattern - with no extra columns, just associations between the two sides - it doesn't scaffold an explicit entity for it, since in most cases that's not needed. Once you change the table and it's no longer identified as "simple", the entity gets scaffolded. You can always add the explicit entity type yourself after scaffolding if you wish. See dotnet/efcore#22475 (comment) for a discussion, dotnet/efcore#4038 also tracks allowing users to opt out of this behavior and always scaffold the join table. |
Duplicate of dotnet/efcore#4038 |
My database has been using always numeric(10, 0) for some historic reasons. Scaffolding set datatype to decimal as it should where our code before EF is using long in C# side. So I have been using IDesignTimeServices to change them to be long in entities. My problem is related to this issue because many to many relation table is not going though IDesignTimeServices so it generates j.IndexerProperty("Lock").HasColumnType("numeric(10, 0)").HasColumnName("lock"); Where I would like to set data type to long instead of decimal because related table ID fields are long. Is there any way to affect how this part of code is generated? |
To reproduce, create database with tables containing many-to-many relation:
Scaffold database using 6.0.1 version of dotnet-ef :
dotnet ef dbcontext scaffold "Host=localhost;Database=eeva;UserName=postgres" Npgsql.EntityFrameworkCore.PostgreSQL --no-onconfiguring --no-build --context EevaScaffoldContext --force
Observed:
Artomadu.cs file is not created.
public virtual DbSet<Artomadu> Artomadus { get; set; }
statement is missing in generated code.
Artomadu table is referenced from Toode table configuring code:
In 6.0.0 version of dotnet-ef those tables caused InvalidOperationException as described in #2118
The text was updated successfully, but these errors were encountered: