Should / it is possible to generate a database schema for certain classes?

I developed several classes using the Visual Studio class diagram. Now I would like to save this data using ORM and possibly other storage mechanisms. I am wondering if there is a way to generate SQL based on the properties in my classes, since they represent the database structure quite well. This will save me from manually entering SQL code and give me a nice start.

I did not start with the database model because I want my persistence to be separated from the actual "domain level" (not sure if this is the correct naming convention).

ORM mapper (LLBLGen) can then generate an encoding based on this scheme, and I will only need to map the generated objects to my persistence interface.

Is it a good idea, or am I on the wrong track here?

I found a tool that seems to do the job (MindScape LightSpeed), but unfortunately it is only available for VS2008.

+1
source share
3 answers

It is a bad idea. Class design and database design are not the same thing.

Personally, I am doing my project at a conceptual level with NORMA , a free Visual Studio add-in. It will generate a schema from a conceptual model and can also generate classes.

The class that it creates is a little hard for my tastes, but it turns out that code generation can be customized if you are not afraid of XSLT.

Due to the nature of modeling the object role, the constraints that you put in the model can be used to derive both the database schema and the class model.

+1
source

There are many ORMs that can generate a database schema from domain model classes. In addition, there are some ORMs designed specifically for this development method. This is the concept of โ€œFirst Modelโ€ or โ€œFirst Code,โ€ and some people feel that this is the future of database application development, since LINQ is now replacing SQL. For example, the next version of the Entity Framework will fully support this concept. I can recommend trying DataObjects.Net , it automatically generates and updates the database schema and supports LINQ queries.

+4
source

It depends. If the project is small, and you have a limited time. Sure. However, the generated code is almost always less repairable than the manual code. This is the same for generating a database schema. Take a look at your project area. Perhaps even create a database and see if you like how it looks. Then decide for yourself. Repeat the assessment for your next project. One size is not suitable for everyone.

+1
source

Source: https://habr.com/ru/post/1276442/


All Articles