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