You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
piskov
changed the title
Strong typing names in data annotations during reverse engineering were possible
Strong typing names in data annotations during reverse engineering where possible
Oct 22, 2023
@ajcvickers oh, that’s rather unfortunate considering:
[InverseProperty] is only needed when there is more than one relationship between the same types (which is far more rare).
If you use pluralizing like with EF power tools, you would never end with ICollection<Item> Item { get; set; } — Items will be used as a name instead and there will be no clash to begin with.
So it seems far more useful nameof was sacrificed for rather rare case (unless there’re others not mentioned in the referenced issue) and I would rather fix those manually if they would ever arise (not that they will seem to appear with pluralizing or not including the inverse attribute if there’s just a single relationship between the entities).
Maybe it is something that can be used at least as an option during scaffolding. Or even maybe implemented manually in T4? In our codebase we do replace all those magic strings manually to nameof.
@piskov The general case is very difficult to solve--we would end up re-implementing significant parts of the compiler. If you're okay with limitations, then the T4 templates are where to do this.
With data annotations you get db-first code like this:
It would be much more error-prone to use “strongly typed”
nameof
version when possible during reverse engineering:PrimaryKey(nameof(First), nameof(Second)]
.[ForeignKey($"{nameof(First)}, {nameof(Second)}")]
.This is especially useful if user would like to rename the property after scaffolding:
Also one could easily see “usages” of the property when it’s referenced not via a magic string but a
nameof
.The text was updated successfully, but these errors were encountered: