-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code First: One-to-one FK APIs should introduce shadow properties #1124
Comments
We shouldn't add new shadow properties if the property referenced by name is not found as this might be a user-error that otherwise would be hard to notice. We could add an overload to explicitly specify a shadow FK, something like
|
Not sure I agree in this case. Seems like it would smooth the usage of a common case. Any opinions @rowanmiller, @divega? |
I'm torn on this one. I think having an FK in the class is a 'pit of success' because we know that shadow state FKs (the equivalent of IAs in the old stack) don't work well in detached scenarios. My gut feel is to not introduce shadow state stuff by convention for these reasons... but I could be convinced otherwise. |
Actually many of the things that were hard about IAs don't apply to FKs in shadow-state. |
@rowanmiller Yeah, not sure. My initial expectation was that the prop would just be introduced. |
@rowanmiller We introduce shadow properties by convention if the app code doesn't specify a property and we don't find one by convention. I don't think we should change this. However, this is not that case. In this case the app code has specified a property which may or may not be in shadow state. If we don't find that property in the model then should we throw or introduce the property in shadow state? Introducing the property is only useful where you want the property in shadow state and you want it to have a specific name, either because the name we chose is not what you want or because we found some other property by convention and you don't want us to use it. To me this is a relatively corner case--or it should be, if our conventions are good. If it is what you want, then a previous call to explicitly put the property in shadow state is not hard to do. Also, I think there is some reasonable chance that you are trying to specify a property not in shadow state, or even a different property in shadow state. So throwing has some value and I don't think we should introduce a shadow state property in this case. But I don't feel strongly one way or the other. |
I would add that one reason to want to use an API like this to specify the name is because you are planning to refer to the FK property in state manipulation code later and you don't want to have to guess how the convention will name it. I personally believe less friction is better and I don't believe it would be harmful if we just synthetize a shadow state property with the name passed to use in this API, but on the other hand I don't think it is a super high priority to do it. |
We could allow this, but record a warning that would be surfaced during model validation, see #1205 |
@AndriySvyryd I think we decided that it would introduce the shadow state property. If it is being used correctly I don't think it is a warning. But the fact we did it should be logged. |
Implemented in #3576 |
Given this:
Where "PersonId" has not been defined, we currently throw ModelItemNotFound; should we just add the shadow key instead?
Should we have an overload of ForeignKey like:
The text was updated successfully, but these errors were encountered: