-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Feature] Add a ShadowAttribute for annotating fluent api #15633
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
There is no heuristic. If you write a string name, if CLR property with that name exist we use it. If not, it's shadow. Reason: If you have CLR property, then we cannot define a shadow property with same name. EntityTypes cannot contain multiple properties with same name. If there is no CLR property then it has to be shadow only. Shadow is all about having backing CLR property or not. There is hardly any choice about user wanting to define the string property as shadow or not since it is controlled by CLR class. Now in the case, user wants to make sure that no accidental shadow property creeps in, using nameof syntax ensure that the string passed is having a corresponding CLR property. |
You say that, but then you define a heuristic:
Note: I'm not trying to argue you with you, just providing feedback on my experience using database-first modeling and trying to get stuff working. The error messages that surface are confusing to me.
Precisely my point. This is doubly confusing with TPH btw, because of the behavior to "guarantee safe name" gets generated. I've had tests that pass with EF Migrations-first approach, but fail with database-first approach. Perhaps I am not describing my problems sufficiently. |
Here is an example that demonstrates the confusion - the other user literally filed the bug with confusing in the issue title: #5377 (comment) |
I will target adding a minimal demo that demonstrates my pain next week. |
There is difference between rule & heuristic. What we have is a rule and not heuristic. |
@smitpatel It's exactly my problem. The issue is that since the API accepts a This is the third time in three weeks I've been tripped up by this. At this point I hope I don't forget this "heuristic"/"rule"/whatever again, but the bottom line is every time I hit these error messages I go searching Google trying to figure out what EF is trying to do. |
Make sure you are not hitting #9171 Apart from that, if error message is confusing, I do not think it warrants even more confusing APIs for customers. The correct solution would be improve error message. |
Fair enough - I was just getting my thoughts out, and this discussion helped me refine those thoughts. I will close this issue since I started a review on #6003 instead. (If that is the wrong workflow, I apologize - not trying to be a PITA.) |
And yes, #9171 is exactly my issue. I see that it was closed, but don't quite see the fix in the PR. Andrew's comments suggest he thought that passing in a single string value was not a valid use case:
The "rare" scenarios @ajcvickers is suggesting seem to be precisely the common scenario when doing database-first modeling. I don't see #9171 as actually fixed as per my comments here. Maybe I am missing something. |
Currently, it is impossible to know from looking at code whether a HasForeignKey string value is referring to a shadow property or a class property. I've been thinking about how to make this more readable, and have an idea:
nameof(MyClass.ThePropertyId)
[Shadow] "thePropertyId"
I think this not only makes the code easier to read, it resolves potential scenarios where the Metadata engine is trying to heuristically decide whether a string is a class property name or a database column name.
Benefits I see:
The text was updated successfully, but these errors were encountered: