Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
Why are entity framework entities partial classes?

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 validation, but I can add validation on the generated entity as well.

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

For the same reason partial classes typically exist at all, code generation.

When code is generated; you don't want your additional methods/properties/whatever blown away, so the designers mark such classes partial to allow users to put additional code in a different file.

In Code-First, the code-generation aspect of EF has largely become obsolete so any EF model classes you create do not need partial.

about 4 years ago · Santiago Trujillo Relatório

0

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.

about 4 years ago · Santiago Trujillo Relatório

0

Marking it as partial allows you to put attributes to that class.
It is handy for example when you need to mark DB generated class as Serializable to be able to store it in Session object (when SQL server mode is used in balanced environments).

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda