It has been long time since my last post. It really dues to the heavy workload in my job(I hope my manager can see thisImage may be NSFW.
Clik here to view.) and my health problem. And with the release of VS2010 and ADO.NET 4.0, I am very interesting to know what is the "best" "orm" I can use in .net world now. I have quoted "best", because I dont want to argue with anyone which one is best for you. I also quoted "orm", because repository factory is not really an orm.
First I'd like to say a little bit of my background in using ORM. In the old days(before microsoft causes any chaos by releasing two unfinished two productions, linq to sql and entity framework), I was really interested in nhibernate, the biggest reason is that it supports many databases and mono(.net framework on linux). But honest speaking, I dont believe nhibernate is a good choice in any medium to large commercial projects. At least your DBA will never let the dynamic queries generated by nhibernate to select, insert or delete tables. Especaily in the production environment of SQL Server, stored procedures are pretty much everything you can access from code. It basically makes nhibernate useless. However, in certain projects, it does add a owo-factor, such as CMS. I created a nhibernate CMS in my previous job about 3 years, it heavily reduced the cost of hosting by using linux mono + mysql, and it also gives marketing people a strong sale point. Because it can be easily fitted into clients' exist IT infrastructure, using exist server, no matter linux or window, using exist db with many choice. If you comes to this page to find a CMS, you may interest to have a look at two open-source nhibernate CMS. Cuyahoga and Eucalypto.
Other ORM I looked at, NBear is another good one. But it apparently dead, the last update in sourceforge for this project was two years ago. What a shame!!! There are many other ORMs, I dont want to list them all, because as you know, I always can find a reason for no using it.Image may be NSFW.
Clik here to view.
Back to our main story, repository factory is a microsoft product (kind of). And released by Microsoft pattern & practice team. It is a great light-weight "ORM". After all, everything I need is a mapping system using stored procedure. Support different database? nope, but the chance of my company changing database is very low, especially after spending 50k+ on license. Support mono? nope, but maybe nobody else knows what mono project is. :p. So it is from microsoft and it does the job. It is a perfect little tool!! Until VS2008 coming out. The GUI tools did not support vs2008. But a separate team release a vs2008 version, and I have to compile from source code in order to fix some bugs. Now vs2010 is released, I think it is a good time to rethink DAL and possible a different ORM to replace.
Linq to SQL and Entity Framework becomes two top choices to me. The reason is simple, firstly I dont want to pay, this push PLINQO (Linq to SQL extension, need CodeSmith, paidware!!!) and XPO out my choice. Secondly they comes from microsoft(it may not be a good reason, but keep the technologies used from the heads of same group people wont be a bad idea). I did a little search on google, and I found out there were quite a lot of poeple discussing the performance of these two ORM. So how much performance penalty will I have for using them? I decided to do a small test by myself.
The test project is simple. A simple database with three columns, TSQL code shown below:
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATETABLE [dbo].[Table_1](
[Id] [int] IDENTITY(1,1) NOTNULL,
[Name] [nvarchar](50) NOTNULL,
[Description] [ntext] NULL,
CONSTRAINT [PK_Table_1] PRIMARYKEYCLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
Five store procedures for insert, select on primary key, select on index key, update and delete.
Create L2S dbml, EFv4 edmx using vs2010. I did not do any optimisations, there are a few performance tips you can find from google. But I personally wont bothered to use them in this test. AS repository factory GUI tool does not work with vs2010, I copied the code from previous project and amend it.
The test result is VERY interesting!
1. I know the first call to EF is slow due to generate views, but the first call to repository factory(RF) is almost as slow as EF
2. I read some post said L2S is slow on inserting, but actually it is not bad
3. L2S and EF on inserting are almost same
4. L2S selecting is slowest
5. RF and EF on selecting are almost same, which takes almost 2.5 times more time comparing with ADO.NET
Here is the result from two runs:
Unit: ms
In summary, I think the overall performance of EF is not as bad as I think. I know it is a still a simple test, with a lot more complex object and mapping, it may comes a totally different result. But this test still give me a little bit confidence to try EF in next project.
I will attach the test code later, and I do like to know what's in your mind. Please do comment.