如何将自定义方法添加到实体框架中自动生成的类?
我有一个具有 2 个方法的类,如下所示:
public class WorkManagement
{
public string DoYourWork(Manager manager)
{
//
}
public string DoYourWork(Employee employee)
{
//
}
}
Manager 和 Employee 是从数据库(在实体框架中)生成的类。我认为它很丑陋,例如,当我需要扩展更多类时,所以我想将其重构为:
public interface IDoWork
{
string DoSomeWork();
}
public class Manager:IDoWork
{
public string DoSomeWork()
{
//
}
}
public class Employee:IDoWork
{
public string DoSomeWork()
{
//
}
}
但是我如何处理自动生成的类?我如何添加这些东西?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自动生成的代码创建部分类。
因此,您只需向分部类添加一个文件,如下所示:
参考 MSDN。
如何:自定义生成的数据对象
Auto-generated code creates partial class.
So you just add one more file to the partial class like this:
Reference to MSDN.
How to: Customize Generated Data Objects