-
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
Unusual navigation names in generated models from existing database #14278
Comments
Navigation name is derived from |
In case of EF6, it generates appropriately i.e. it will generate |
I have same issue where I have used the foreign key column names not matching the primary key column name. e.g. User table has User_ID as PK When querying the DB all is well on one entity but add include to query and we hit a problem. It keeps tryingto add a column name matching the PK column name from the FK table. |
@sc-vudo This looks different from the issue reported here. Can you please file a new issue, including a small, runnable project/solution or complete code listing that demonstrates the behavior you are seeing. |
No longer repros with 7.0. Generated code is: public partial class Student_Detail
{
public int ID { get; set; }
public string? Student_Name { get; set; }
public virtual ICollection<Book_Detail> Book_Details { get; } = new List<Book_Detail>();
} public partial class Book_Detail
{
public int ID { get; set; }
public string? Book_Name { get; set; }
public int? Student_Id { get; set; }
public virtual Student_Detail? Student { get; set; }
} |
When model classes are generated for existing database, column names are in correct in the case as described below.
I have a sample database, say, school database which has two tables Student_Details and Book_Details
Book is issued to multiple students at different times, so one book to many students relationship is there. Now in Book model class, navigation property name for Student is generated incorrectly. Ideally, it should be Student_Details whereas it is generated as Student_
Script of sample database:
Steps to reproduce
Run command in PM Console:
Scaffold-DbContext "Server=.\SQLEXPRESS;Database=school;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -UseDatabaseNames -Context schoolEntities
The same behavior is there if run from command line instead of PM Console.
Here are genereated model classes. Please note, property name in Book_Details class should be Student_Details, whereas it is Student_
Further technical details
EF Core version: 2.1.1-rtm-30846
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017
The text was updated successfully, but these errors were encountered: