Repository navigation
Conversation
…candidate NavProp names.
There was a problem hiding this comment.
Have been thinking about this and will update to strip off the "Id" only if it is specifically "Id" or "ID". "id" might be the end of some other word and "iD" just seems weird.
There was a problem hiding this comment.
Yes, this feels brittle. Instead of EndsWith("Id") can we do something like EndsWith(principalPKColumnName)? This might also allow us to handle composite keys better too. E.g. EmployerId1, EmployerId2 could become Employer instead of just Company.
It also doesn't seem to work well with databases that name things using underscores like EMPLOYER_ID.
I wonder if it's worth even trying to do this in v1. In EF6, we just uniqified the principal table name.
There was a problem hiding this comment.
There's a whole lot more we could on pluralization/singularization. But discussed that with @rowanmiller a while back and decided not to get into that - at least for this release.
As for priority - #1076 is marked as pri0. Again I'd defer to @rowanmiller on that. And unfortunately just uniquifying the principal table name is what causes the Employee, Employee1 situation which is the main complaint of that issue.
Not sure I follow on the composite key scenario. If the foreign composite key is {EmployerId1, EmployerId2} and the principalKey is (CompanyId1, CompanyId2} how does EndsWith(matchingPrincipalPKColumnName) help me come up with "Employer" as the NavProp name? The problem with composite keys is you have to pick one name from all the column names - and it's hard to guess what would be most helpful - I could try to find a common prefix that all the column names share and then strip off "I[dD]" and uniquify that? An alternative is to use the name of the constraint in the database - but that's usually something unhelpful like FK_Customer_Employee_1 i.e. all it tells you is the names of the tables at either end. And it doesn't have to follow that pattern - the DBA is free to name it whatever they want.
There was a problem hiding this comment.
Also am happy to extend it to look for EndsWIth("_id", StringComparison.OrdinalIgnoreCase) as well.
There was a problem hiding this comment.
I talked with Rowan, and I'm fine with however much of this we want to implement. We should, however, review what we do by convention in a (possibly ad-hoc) design meeting.
There was a problem hiding this comment.
@bricelam Sure. No problem - happy to review.
|
Our usage of DI here (including the Migrations commands) doesn't gel well with the rest of the stack. We should look at ways of reusing more of the common components and patterns. |
|
Re DI comment - agreed. I'll raise an issue to look at it as a whole. |
|
|
|
Checked in - commit d2f7162. |
Addresses #1076 and #1672.
Make ModelUtilities a service and change the algorithm for producing candidate NavProp names.