SQL attack! Let's start ignoring the existence of Linq! Strong type, no entity class required! (Automatic entity of Moon. Orm: GetAutoEntities)

Source: Internet
Author: User
Document directory
  • 1. Moon. Orm's Automatic Object Query Solution
  • 2. Running result
  • 3. Methods
  • 3. Download demo
1. Moon. Orm's Automatic Object Query Solution
Using System; using Moon. orm; using System. windows. forms; using North; using System. diagnostics; using System. collections. generic; namespace Demo {class Program {public static readonly Stopwatch sp = new Stopwatch (); public static void Main (string [] args) {Moon. orm. globalData. AUTO_COMPLIE_DIRECTORY_PATH = Application. startupPath; string SQL = "select top {0} * from Orders Left join Order_Details on Order_Details.OrderID = Orders. orderID "; object ret = DBFactory. getAutoEntities (SQL, null, 1); sp. restart (); dynamic ret2 = DBFactory. getAutoEntities (SQL, null, 200); sp. stop (); Console. writeLine ("dynamic entity:" + sp. elapsed); sp. restart (); string sql2 = "select top 200 * from Orders Left join Order_Details on Order_Details.OrderID = Orders. orderID "; var list = moontemp. entityGetByAdonet. getList (sql2, DBFactory. defaultDB); sp. stop (); Console. writeLine ("Pure ado.net:" + sp. elapsed); Console. write ("Press any key to continue... "); Console. readKey (true );}}}
2. Running result

We can see that the efficiency is similar to that of pure ADO. NET, and it is convenient for everyone to think about it. It is also a strong type, so we ignore the issue that <the anonymous type cannot return to the MVC View>

Requirements:. net 4.0 or above.

We can use it like this: decimal newMoney = ret2 [2]. SumMoney + 100;

Configuration File Settings: (Note not to comment)

Note that the last path has \

3. Methods

Object GetAutoEntities (string sqlTemplate, string className, params object [] values)

SqlTemplate: SQL template. The same template can be used for the same logic to provide query efficiency.

ClassName: This is a random name used for caching. It can also be null, but it is less efficient. if you assign a value to it, clear the moon_temp file in the compilation path when the SQL template changes .... dll

Params object [] values: used to replace the parameters in the template. Note that the parameter format of the template is {0} {1} {2}

 

3. Download demo

Note that you need to attach the database to your database, and change the connection string in the project.

Download projects and databases

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.