The primary reason for using an ORM is to provide a layer of abstraction from your database. As with most abstractions in software development, an ORM might be considered a leaky abstraction.
The goal of implementing IAggregate for the different ORMs is to provide insight into how different tasks you perform in your high level language are converted and handled by the ORM. IAggregate provides two methods that do standard things like get counts or averages. It then allows us to provide different implementations that demonstrates differences in generated SQL and timings based upon an approach. Generally ApproachOne is the desired one and ApproachTwo may demonstrate a bad practice.
Here is a simple example of simple query that returns counts in a table via NHibernate:
Can you spot the difference? Right next to each other, it is probably fairly obvious however if you are new to programming, or don’t know too much about SQL, you might not realize the problem.
With the latest release of ORM SmackDown we attempt to expose some of the differences through the implementation of IAggregate for the different ORMs.
When running the first query we generate the following SQL:
As with the second we generate different SQL:
It should be fairly obvious which result is desirable.
As this is an on-going research project, that hopefully others will find somewhat educational, please feel free to provide feedback on better implementations for different ORMs.
Post a Comment