How to Build An ORM framework and An ORM framework

Source: Internet
Author: User

How to Build An ORM framework and An ORM framework

Many people do not recognize third-party ORM, because the considerations are not comprehensive enough and there is no guarantee for large user-base ORM. This is undeniable.

However, there are often many shortcomings in the user-base ORM. Let's look at the two most popular ORM.

1. EF

EF has enough performance, but the overall performance is still different from that of lightweight ORM. If there is no difference, there will be nothing about Dapper.

2. Dapper

Good performance, good compatibility, but there are too few syntaxes. Basically, you need to write SQL statements or expand your own. You may not be able to use any third-party ORM on your own, it is easy to discover problems and make changes.

 

My ORM journey 1. Thank you for your help.

First, I would like to thank Shanghai blue light Data Technology Co., Ltd. for giving me the role of a constructor to allow the. NET Department to use my technical framework.

The strong support of the boss of the 200th sign software not only used by their employees, but also helped me transfer the support

My friends in group 3 (225982985) asked me a lot of expensive questions and suggestions for improvement.

Fourth, chloe. The author of ORM, both of whom are passionate about ORM.

 

2. Talk about some pitfalls encountered in developing the SqlSugarORM framework.

These pitfalls I found that some other ORM in the blog Park also exists, so I will share these issues one by one and hope more people can point out the shortcomings of SqlSugar.

 

(1) Avoid plan failure during SQL Execution

What is an SQL Execution Plan, simply put, is to let the SQL Server know more clearly what you want to do and save your operation steps, the next time you encounter the same SQL statement, you can use the same operation steps, greatly reducing the SQL operation steps and improving the performance. The performance gap may be multiplied.

The reason for the high performance of parameterized SQL statements is that the advantages of the SQL Execution Plan are brought into play by calling the system storage process sp_executesql.

For example, if the length of name is 11, the nvarchar number is dynamic because sqlparameter does not specify the Size. Therefore, the SQL Execution Plan is invalid because the normal performance test is hard to test, in this case, the SQL Execution Plan will be disrupted. The more parameters, the larger the parameter length, the more obvious the performance gap.

However, tests with a fixed length cannot be found.

 

Solution:

Set SqlParameter size to <4000

Set all to 4000. EF and Dapper are doing very well at this point.

 

For example, if id <1 & id> 0 is used to process two identical name parameters, id <@ id and id> @ id + Random Number

Once a random number is added, the execution plan cannot be entered.

Solution:

Auto increment id <@ id and id> @ id1

 

 

2. Processing of converting data types into objects

In this regard, Dapper is the best, and EF also provides a very clear error message.

Why is Dapper the best? Because Dapper can convert the int of data to a string in the object class. When the database is converted from string to int, a very clear error message is provided.

At present, third-party ORM has not done a good job in this aspect.

Solution:

I need to make a very detailed type determination section. My approach is to process it before Emit generates Dynamicbuilder, compare it with the database type and entity class body, and throw an exception in advance, no exceptions occur. The EMIT object will be stored in the cache and will not be executed after being pushed.

 

 

 

3. Performance breakthroughs

Simply using Emit to convert DataReader into List <T>, third-party ORM is basically faster or equal than Dapper.

This is the best test method to query 1 million pieces of data at a time after pushing, but note that if the DataReader index is used, performance loss will occur.

GetValue and indexer are both Object types. After conversion, a box is generated (the OBJECT is converted to a value type). SqlSugar can be improved in this respect, thanks to Chloe. ORM author helped me find this problem

 

4. Lambda resolution Performance

How long does it take for Lambda to parse SQL statements,

Test method:Only one data record is queried at a time, and one more WHERE condition is set. The number of executions exceeds 10000.

Solution:Expression. Lambda (exp). Compile (). DynamicInvoke ();

Using this method will bring about 10 times worse performance, and it is easy to measure the performance bottleneck According to the above test method.

The shorter the execution time, the more execution times, the easier it will be.

 

 

Release to nugetless than 2 weeks

 

 

I have submitted so many modifications

 

 

 

SqlSugar usage and Description: http://www.cnblogs.com/sunkaixuan/p/5654695.html, welcome your advice

 

Finally, I just want to say that it is not a third-party ORM that cannot be used, but that you have not pointed out the problem. The open source code is to make everyone progress and make improvements together.

As long as the author is passionate and motivated, what are the concerns.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.