3

I have a question about programming practices regarding entity framework classes.

When I create the .edmx file, it creates the class, but when I update this file, all methods I made for the this class are gone.

My question is: Should I create another class, that contains all the methods? In this case, the entity framework class would only have attributes?

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
ernesto petit
  • 1,436
  • 1
  • 14
  • 19

1 Answers1

9

Entity Framework (Model-First) generates a code file for you. Any changes you make to that file will be lost the next time it is generated. There's even a warning to that effect in a comment at the top of the file.

However, those classes are marked partial (as most generated classes are) so you can have a separate code file that contains the remainder of the class definition (ie, your methods). See MSDN for more information on partial classes.

You can also write other classes that take the data objects as parameters. This is usually how you do this, as EF objects are typically left data-only.

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117