Scaffolding naming problem in .Net 5
Good day. I found some strange behavior using EF "scaffolding-dbcontext" command. Some foreing keys are translated in very different ways.
Example:

Reproduce: Use northwind DB: https://github.com/microsoft/sql-server-samples/blob/master/samples/databases/northwind-pubs/instnwnd.sql
Scaffold command: Scaffold-DbContext "Server=MyServer;Database=NorthwindDemo;User Id=sa;Password=MyPassword;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context NorthWindContext -DataAnnotations -UseDatabaseNames -noPluralize
Detail description:
After generating, EF uses 3 different types of navigation property names.
Rule A: in this case, DB column Orders.ShipVia is translated to
public virtual Shippers ShipViaNavigation { get; set; }
This case happens because column "Orders.ShipVia" has a different counterpart in FK: "Orders.ShipVia" different PK column name in "Shippers.ShipperID" (ShipperID <> ShipVia)
Rule B: in this case, column "CustomerCustomerDemo.CustomerID" is translated as
public virtual Customers Customer { get; set; }
(note, here is not "Navigation" name like "RuleA"). Seems like when the FK matches other table PK there is other rule. This case "CustomerCustomerDemo.CustomerID" matches PK "Customer.CustomerID" (CustomerID = CustomerID)
Rule C: in this case, column "CustomerCustomerDemo.CustomerTypeID" is translated as
public virtual CustomerDemographics CustomerType { get; set; }
Note here that this rule is very similar to "Rule B": FK and PK shares the same name in DB. But this time the navigation property converted from db column "CustomerTypeID" to navigation property "CustomerType". The strange here is both FK and PK are the same like "Rule B" but the output is different.
Problem: this is confusing and leads extra handwork to fix multiple cases. Better is having just ONE rule (let's say rule A) for navigation properties, not 3 rules. I'm not sure if this is considered bug or simple no standard. Suggestion: use "Rule A" as default, or at least have a additional parameter to maintain some standardization in naming. Thanks
EF Core version: Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: (NET 5.0) IDE: (e.g. Visual Studio 2019 16.3)
EDIT: Issue closed. Explanation done is incorrect. As @smitpatel commented, the rule for navigation properties is: The FK column ends with ID? a)Yes, Navigation class name = "ColumnName" minus "ID". b)No: Navigation class name = "ColumnName" plus "Navigation". Many thanks to @smitpatel
Since it is common practice to use Id suffix for keys (like how CustomerID is defined above), the rule in place is that FK name is navigation name + Id if FK name ends with Id. If it doesn't know that we use FK name + navigation. There is no relation to PK property name. These rules match commonly used pattern for naming and we unlikely to change it now since adding Navigation to every navigation property is probably worse.