Why POCO Classes generated EF 4.x DbContext Generator for C# are Partial?

a 夏天 提交于 2019-12-25 07:40:51

问题


I'm using EF 4.3.1 and "EF 4.x DbContext Generator for C#" for creating POCO using T4.

the classes generated are:

namespace MyProjects.Models
{
    public partial class ReCategory
...

Why the class is PARTIAL?

POCO are not classes without the plumbing of EF?

If you think this question is not appropriate please comment I will remove it, thanks for your time.


回答1:


Why shouldn't they be? Just about every code generator these days will generate partial classes, so that you can add your own members to the class - in a separate file.

If these classes have to be regenerated, the file they are in will be completely replaced - but your customizations will survive.


Partial Class Definitions:

There are several situations when splitting a class definition is desirable:

  • When working with automatically generated source, code can be added to the class without having to recreate the source file. Visual Studio uses this approach when creating Windows Forms, Web Service wrapper code, and so on. You can create code that uses these classes without having to edit the file created by Visual Studio.


来源:https://stackoverflow.com/questions/11202016/why-poco-classes-generated-ef-4-x-dbcontext-generator-for-c-sharp-are-partial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!