Why are entity framework entities partial classes?

后端 未结 3 1368
不思量自难忘°
不思量自难忘° 2021-02-07 14:59

I recently began using entity framework, and I noticed that generated entities are partial classes. What are the uses of that? I googled a bit and people mostly speak of validat

3条回答
  •  既然无缘
    2021-02-07 15:31

    partial is added to generated entities for customization.

    In situations when you wish to add your own methods to classes produced by code generators, including EF, it is a good idea to put your implementation in a separate file, so that you wouldn't run the risk of losing your customizations each time the code is re-generated.

    Without partial developers wishing to customize the class would have to use work-around techniques, such as applying Generation Gap design pattern.

提交回复
热议问题