n-tiers & ORM & how to implement ORM
Usually I'm developing application in tiers (DAL, BLL, UI) using VS.NET 2008 with .net framework 3.5. For data access, I'm using Enterprise Library 4.1 and logging using log4net.
I've heard about ORM, and interesting to implement ORM in my programming, how to do that? Is that any impact to the performance?
I know 2 ORM, NHibernate and Entity Framework. from www.ormbattle.net NHibernate performance is not good, and Entity Framework I think it's too 'young' to be used in VS.NET 2开发者_如何学Go008.
What about LINQ2SQL, is it one of ORM tools? but the performance is too slow that using conventional way.
It may be worth looking at some of the so called 'micro ORM' solutions such as Dapper, PetaPoco or Massive as alternatives to NHibernate, Subsonic, Linq2Sql, EF, etc.
This answer holds some insightful info into the experience of using Subsonic vs PetaPoco.
Linq2Sql is no longer being developed. They'll probably never get rid of it, but they're not adding to it anymore; it's deprecated in favor of MSEF.
NHibernate is probably as performant as any ORM. Keep in mind that most ORMs use a lot of reflection to create objects, get and set properties, digest Linq expressions, etc. You're not going to get away from it without reverting to ADO.NET.
However, NHibernate does have a significant "N+1" problem with its lazy-load "PersistentBag" proxy. When an entity that contains a collection of child entities is instantiated by NH from data, its child collection is set to a proxy object that doesn't actually hold the data; it just knows how to make more calls to get that data. When you ask for each element of the child collection, NHibernate makes another call to the DB. This results in "N+1" total roundtrips to the DB, where if you architected your DAL yourself you would probably handle the same case in 2 roundtrips; one for the main object and one for the child collection.
If you understand this problem, you can work around it by coding a second query for the child elements instead of having NHibernate initialize them for you. You can still make it work lazily.
You can start with http://bltoolkit.net. Good and fast data access library with some nice ORM features. Great for migration legacy code from pure ADO.NET.
精彩评论