n-tiers & ORM & how to implement ORM

陌路散爱 提交于 2019-12-13 01:53:57

问题


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 2008.

What about LINQ2SQL, is it one of ORM tools? but the performance is too slow that using conventional way.


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/6296555/n-tiers-orm-how-to-implement-orm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!