How to add a custom method to an automatically generated class in Entity Framework?

I have a class with two ways:

public class WorkManagement { public string DoYourWork(Manager manager) { // } public string DoYourWork(Employee employee) { // } } 

Manager and employee are classes created from a database (in the Entity Framework). I think this is ugly, for example, when I need to extend a class, so I want to reorganize this into:

  public interface IDoWork { string DoSomeWork(); } public class Manager:IDoWork { public string DoSomeWork() { // } } public class Employee:IDoWork { public string DoSomeWork() { // } } 

But how can I deal with automatically generated classes? How do I add this thing?

Thanks.

+8
c # design-patterns entity-framework
source share
1 answer

Automatically generated code creates a partial class.

 public partial class Manager : EntityObject 

So, you just add another file to the partial class as follows:

 public partial class Manager : IDoWork { public string DoSomeWork() { } } 

Link to MSDN .

A practical guide. Configure generated data objects

+8
source share

All Articles