After installing vs2008 beta2 today, I can't wait to try out the ORM function in LINQ. After a preliminary attempt, I found that the ORM in LINQ is still very good. I checked the system through reflection. data. LINQ. DLL found that the ORM in LINQ completes or ing Using Reflection. Based on this, I began to doubt the performance of ORM in LINQ. To further study the problem, I wrote a simple test. In a transaction, I used datarabbit 3.0 and LINQ to SQL to insert 1000 pieces of data into the database's customer table in the form of an Orm, let's look at the time required.
First, the customer structure is as follows:
The test code is as follows:
(1) Use the linq orm: Dataclasses1datacontext DB = New Dataclasses1datacontext( " Data Source = 127.0.0.1; initial catalog = linqdb; persist Security info = true; user id = sa; Password = chenqi " );
Datetime Start = Datetime. Now;
for ( int I = 1000 ; I 2000 ; I + )
{< br> dB. MERs. add ( New customer {id = I, name = " Peng " , zipcode = 434100 });
}< br> dB. submitchanges ();
DatetimeEnd= Datetime. Now;
TimespanSpan=End-Start;
This. Label1.text=Span. totalseconds. tostring ();
(2) Use the orm of datarabbit3.0
Datarabbit.DataconfigurationConfig = New Datarabbit.Dataconfiguration(Datarabbit. databasetype. sqlserver, " 127.0.0.1 " , " SA " , " Chenqi " , " Linqdb " , Null );
Datarabbit. application.TransactionscopefactoryTransactionscopefactory = New Datarabbit. application.Transactionscopefactory(Config );
Transactionscopefactory. newtransactionscope ( False ). Newormaccesser < Linqtest. myorm.Customer > (). Insert ( New Linqtest. myorm.Customer( - 1 , " Peng " , 434100 ));
Datetime Start = Datetime. Now;
Using (Datarabbit. application.TransactionscopeScope = Transactionscopefactory. newtransactionscope ())
{
Datarabbit. Orm.Iormaccesser < Linqtest. myorm.Customer > Accesser = Scope. newormaccesser < Linqtest. myorm.Customer > ();
For(IntI= 2000; I< 3000; I++ )
{< br> accesser. insert ( New linqtest. myorm. customer (I, " Peng " , 434100 ));
}
Scope. Commit ();
}
DatetimeEnd = Datetime. Now;
TimespanSpan = End - Start;
This . Label2.text = Span. totalseconds. tostring ();
Clear the customer content. After you click the form button (first LINQ, then datarabbit) for the first time, the interface is displayed as follows:
Clear the customer content again. After you click the form button (first LINQ, then datarabbit), the page is displayed as follows:
Compared with result 1, we found that the linq orm was optimized very effectively at runtime, and the performance was nearly doubled. If we repeat the experiment, we will find that the time required for the LINQ and datarabbit will basically not change.
From the stable results, the orm performance of datarabbit3.0 is nearly twice higher than that of LINQ. It is expected that such a result will appear. Datarabbit3.0 uses Emit for dynamic generationProgramThis can completely avoid the performance loss caused by reflection, while it is reasonable that the internal implementation of ORM by reflection in LINQ to SQL causes a slight reduction in performance.
One of the following aspects of Using Reflection to implement ORM in LINQ is as follows:
(System. Data. LINQ. changedirector + standardchangedire's insert method implementation)
Maybe there may be more efficient methods to use LINQ Orm, but I have not found it. If you know, please leave a message to tell me.
The test source code is downloaded from this directory.