S
S
stcmd042362017-10-18 16:16:36
C++ / C#
stcmd04236, 2017-10-18 16:16:36

How to avoid multiple class creation in c# web api?

Good afternoon! There is an experimental project on aspnet web api. ORM EF6. For example, there is a class Order, OrderView, OrderDataBindingModel. Order is a class that is used in EF. OrderView to create a response to the client. OrderDataBindingModel to receive data from the client. The difference between the class Order and OrderView is only in the fields i.e. some fields are missing from OrderView. And the OrderDataBindingModel is different in that they contain DataAnnotations rules to check the validity of the data received from the client. For each entity, you will have to create three classes in the simplest situations.
How can you avoid multiple class creation? I read about programming patterns but I don’t know how to apply in this case.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
eRKa, 2017-10-18
@stcmd04236

In general, you are correct. There is a layer of models that are entities, there is a layer of models that display data, there is a layer of dto models. It's always the same with my projects. In vain you think that you are multiplying them, they are in different layers (modules), you can consider them as different domain models. For large and complex projects, this is justified. And although all classes may seem the same from the outside, they are different, because. belong to different domain models and perform different functions.
If your project is small, then you could get by with one layer for working with ORM and not complicate the code.

D
Dmitry Eremin, 2017-10-18
@EreminD

One class per entity and repository

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question