As the principles of the benchmark have been laid, I can now move to implementations. What follows are code snippets of each test case, with comments where necessary.
The ADO.NET test is straightforward:
Note that the materialization is done manually but in addition, a dummy StringBuilder accumulates some data for each read record. This string builder is not important with this ADO.NET test but in later tests the intention of it will be to simulate that the data is actually used somehow (not only read from the database).
This time also the test is straightforward. The model has been generated automatically, both the data context and entities.
Note that this time I perform a “warmup” – this is to make sure that no internals of the ORM depending on the “first run” will influence the measurement.
EF5 Model First
This test is similar to the previous one – model is generated with the help of the designer, both object context and entity classes are available.
What is interesting is that this time I consider tracking as an important factor and I make sure that it can be turned off. Turining tracking off has some serious consequences for change tracking but since we only select the data, the only observable difference would be that turning tracking off will make the execution much faster.
I also make sure that views are pregenerated (by forcing the pregeneration with the EF Power Tools).
EF5 Code First
For Code First approach, we create entities and the dbcontext manually
The test now becomes
Note that in this case there is no easy way of turing tracking off on the db context, instead, an extension AsNoTracking is used.
For nHibernate, model has to be created manually
as well as mappings
and the test is
What is interesting here is that I am trying to compare the statefull and stateless session with the hope that stateless sessions would somehow correspond to EF’s “no tracking” in a sense that a stateless session should fetch rows from the database faster.
In the next entry we will analyze results.