10

I have a class with 2 methods as follow:

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

    public string DoYourWork(Employee employee)
    {
        //
    }
}

Manager and Employee are classes generated from database (in Entity Framework). I think it's ugly, for instance, when I need to extend more class, so I want to refactor this into:

 public interface IDoWork
 {
    string DoSomeWork();
 }

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

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

But how I can deal with auto-generated classes? How I add these thing?

Thank you.

2
  • 1
    Pretty sure the classes are partial classes that are generated, so you can extend the class by creating your own partial class for Employee/Manager. Commented May 18, 2011 at 2:40
  • @Phill: never know about that. Thank you :) Commented May 18, 2011 at 3:31

1 Answer 1

9

Auto-generated code creates partial class.

public partial class Manager : EntityObject

So you just add one more file to the partial class like this:

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

Reference to MSDN.

How to: Customize Generated Data Objects

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.