Should I modify Entity Framework generated classes?

c# entity-framework entity-framework-6

Question

I have generated my data model from database using Entity Framework, but there are some minor style-related things I'd like to change. For example:

public Nullable<int> eventId { get; set; }

this is a part of the generated C# code, and I'd like to, let's say, change the property name to EventId.

I'm just wondering if doing this in an EF environment is safe, or if it will backfire later and punch me in the face...

1
1
8/8/2018 8:39:36 AM

Accepted Answer

If you were to auto-generate the classes again in the future, your changes would be lost. This has happened to me with a production piece of software where I appended a computed property into a generated class:

public string GetOtherProps => $"{this.prop1}, {this.prop2}";

and then referenced that throughout our application.

The classes were regenerated for some reason and suddenly there's hundreds of Unknown Reference Errors throughout our software.

3
8/8/2018 8:45:33 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow