Skip to content

Make ModelUtilities a service and better NavProp names - #1751

Closed
lajones wants to merge 1 commit into
devfrom
lajones-150303_Issue1076_NavPropNames_01
Closed

lajones wants to merge 1 commit into
devfrom
lajones-150303_Issue1076_NavPropNames_01

Conversation

@lajones

@lajones lajones commented Mar 4, 2015

Copy link
Copy Markdown
Contributor

Addresses #1076 and #1672.

Make ModelUtilities a service and change the algorithm for producing candidate NavProp names.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also am happy to extend it to look for EndsWIth("_id", StringComparison.OrdinalIgnoreCase) as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bricelam Sure. No problem - happy to review.

@bricelam

bricelam commented Mar 6, 2015

Copy link
Copy Markdown
Contributor

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.

@lajones

lajones commented Mar 6, 2015

Copy link
Copy Markdown
Contributor Author

Re DI comment - agreed. I'll raise an issue to look at it as a whole.

@bricelam

bricelam commented Mar 9, 2015

Copy link
Copy Markdown
Contributor

:shipit:

@lajones

lajones commented Mar 10, 2015

Copy link
Copy Markdown
Contributor Author

Checked in - commit d2f7162.

@lajones lajones closed this Mar 10, 2015
@bricelam
bricelam deleted the lajones-150303_Issue1076_NavPropNames_01 branch March 13, 2015 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants