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
I am a newcomer to Entity Framework Core and just getting into using my Entity Framework Core models as the primary source for the schema of my database.
I initially created this model using dotnet ef, pulling the model from an existing database.
When modifying my schema I found that I encounter issues when renaming properties within an IDE. It would not catch the name within quotes of a decorator, for example: [InverseProperty("apartments")]
If I change the property name of apartments that the inverse property is pointing to than I have to go though my model and change every string. this is very annoying.
IDEs have a solution for this. I am using Rider and I can just hit f2 and modify the name of a variable. but when dotnet ef creates a model it hardcodes these values in such a way that it's hard for an IDE to detect that that is supposed to be a reference to a variable name.
Solution:
C# has a solution: nameof. When dotnet ef wants to reference a class name it should be using nameof(structureTypes.apartments) instead of "apartments". This approach is much more data-driven and is easier on IDEs
The text was updated successfully, but these errors were encountered:
making this conversion in my code base manually, and you probably want to use nameof(Models.StructureTypes.apartments) as StructureTypes is a common name name for objects in the data model
@hutonahill We investigated using nameof before, and even tried it. It did not work out well--see ##26588. Scaffolding to use the model builder APIs will generally make the code easier for refactoring tools to understand.
Problem:
I am a newcomer to Entity Framework Core and just getting into using my Entity Framework Core models as the primary source for the schema of my database.
I initially created this model using
dotnet ef
, pulling the model from an existing database.When modifying my schema I found that I encounter issues when renaming properties within an IDE. It would not catch the name within quotes of a decorator, for example:
[InverseProperty("apartments")]
If I change the property name of apartments that the inverse property is pointing to than I have to go though my model and change every string. this is very annoying.
IDEs have a solution for this. I am using Rider and I can just hit f2 and modify the name of a variable. but when
dotnet ef
creates a model it hardcodes these values in such a way that it's hard for an IDE to detect that that is supposed to be a reference to a variable name.Solution:
C# has a solution:
nameof
. Whendotnet ef
wants to reference a class name it should be usingnameof(structureTypes.apartments)
instead of"apartments"
. This approach is much more data-driven and is easier on IDEsThe text was updated successfully, but these errors were encountered: