On the Good and Bad of Code Generators

    Five years ago, the dynamic software code generator was a very convenient tool, and many developers engaged in the C# language have used this tool, including myself of course.

    In the past, the development model was centered on the database, and the database was designed first, and then the code was written. The dynamic software code generator was born in this context.

    You only need to design the database schema, and then use the software code generator to generate the data access layer code with one click, which is very convenient. (Although DynamicSoft has a business layer, I think it is tasteless. It is just a simple wrapper for the data access layer, and has no practical significance)

This is very attractive to developers who don't want to write tedious database operations manually.

  Below I rely on my own experience to summarize the software code generator from two aspects: good and bad.

Advantage

  1. Automatically generate entity classes and data access code.

  Second, most database operations can be satisfied, including paging

  3. Rapid development

disadvantage

  1. The generated entity classes lack associativity, and most actual projects require navigation

  2. Lack of database transaction support, all operations are single-table

  3. Poor support for some types, such as date and new datetimeoffset

  Fourth, the data queried is based on DataSet rather than entities, which makes people feel very strange

  5. To modify the database structure, you must manually generate the code. If you modify the files generated by the software, wait and cry.

  6. It does not support generating database from code (Code First).

 

  There is a very famous adage in IT: there is no silver bullet. There is no one-size-fits-all solution, no panacea. Code generators are not a silver bullet. Many years ago, I heard the saying that code generators can replace developers.

There are two reasons for saying this: one, your developers are too bad, similar to a code generator; two, your product is too bad, you can do it with a code generator. Whatever the reason, the person who says that sucks, haha! 

  With the rapid development of IT technology, many excellent tools have emerged to replace code generators. The landlord is doing .Net, and I recommend a few good tools to everyone. If you know it, you will be in charge of the job, and if you don't know it, you will learn it.

The first is Microsoft's Entity Framework , followed by NHibernate . Entity Framework is the son of Microsoft and integrates well with Microsoft's own Sql Server. NHibernate is open source, supports many databases, and has good portability.

If you don't like these heavyweight frameworks, then consider using ibatis and dapper. As far as the landlord is concerned, if I have a choice, I will consider using Entity Framework and Linq. Linq is so awesome, I have to admire Microsoft.

    Open source location: https://github.com/aspnet/EntityFramework6

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324454308&siteId=291194637