-1

I have searched the web about the benefits of creating new entities, creating new entities vs Customizing existing entities etc. but I did not find anything which strongly supports the things and very specific where to use custom entity or where to create new entity in C#.

I have some points in my mind which I want to share with you and want your feedback and the supporting link for that.

Advantages of creating new entities are you can define your own class and use it as an entity. It allows you to avoid partial keyword in class type definitions. Not using partial keyword will help to compile your application faster by reducing its processing overhead. The other benefit of not using partial that we do not get more than one implementation of the same function by mistake, as we can avoid this using inheritance.

Secondly, sometimes modifying the thing is more typical than implementing it from scratch.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ankur
  • 161
  • 4
  • 14

1 Answers1

1

Normally when you use an Entity Data model with Database First or Code First, the code generated will contain your scalar properties and navigational properties and a bunch of events and partial methods that you can use.

If you don't want the EF to create this you have to write it yourself and you will end up with the same code that could also have been generated.

I've never hearth of the reasons why you are not willing to use the partial keyword. It's a nice way to separate the generated code from your own handwritten extensions. I wouldn't worry about compile time. If you look at the Intellisense when accessing the members of a partial class you will see that the compiler has already figured everything out in the background without you even noticing it.

So if you use a Database First or Code First approach there is nothing wrong with letting the Entity Framework generate the entities for you. Of course you still have a lot of choices in how to generate the code. The POCO templates will generate nice, clean classes with minimal coupling to the database.

If you really want to create your entities complete from scratch you can always look at Code Only. This is a technique where the Entity Framework will infer the database mapping from your POCO entities to the database (with some help if necessary through a fluent API).

halfer
  • 19,824
  • 17
  • 99
  • 186
Wouter de Kort
  • 39,090
  • 12
  • 84
  • 103