.net - NHibernate vs. EF 4.1+ -
i trying decide pros , cons of 2 orm in area.
- compatibility sql server 2008 r2 & 2012.
- this important don't have resources debug poor support of existing ms technology stack.
- also planning ahead since 2012 pretty out , plans migrate in place.
- support .net 4.0 , 4.5 (upcoming)
- again important pretty same reason above.
- transaction handling , table hints eg. forcescan forceseek, read uncomitted.
- a lot of times query optimizer job well, other times want flexibility tell do.
- support conversation, self tracking attach & detach
- this fundamental. hate keep session open prolonged period. in distributed computing/web farm environment.
- ability handle code first development, create , update schema without destroying data.
- ef 4.1 seems wanting in regard, although 4.3 leap , bound better. liking data annotation better seperate mapping classes in nh. reason being want able send in class , there able create persistence model without widening method mapping classes.
- support irepository pattern
- support linq
- somewhat tied (6) above want support linq. don't want developers muck around lower level implementation , getting ourselves stuck 1 particular orm
- performance
- support bulk crud operations, without having load data application layer. eg. want increment rows in column of particular table 1. don't want load memory, , increment rows 1 one. crazy such simple operation. linq2sql used have magiq handle sort of thing, nh , ef have?
- caching, eager loading, lazy loading, navigation properties.
- let me frank hate these things when done implicitly. reason being it's hard distinguish cached, stale new. in ef drop navigation properties, because don't want these properties loaded top 5, because that's current operation needs, further down stream developer attempts count inaccurate.
- so personal policy - soa shall stateless unless there reason otherwise. if need referencing data, persistence. slower code more readable , flexible.
- similarly caching. complex enough in distributed environment, want caching very explicit. if developer wants code against cache, should so, not code against orm, , make appear if pulling fresh data persistence when in fact getting stale data.
- now question is, nhibernate have concept/abstraction make caching, eager/lazy loading more explicit 1 available in ef. in case don't care ease of development, care more clarity , explicitness.
also don't care oss vs. propietary argument. team cannot afford time peek under hood , start messing around other people's code. care more "it works" angle else.
you use bltoolkit ;) -> http://www.bltoolkit.net/doc.linq.ashx
just take 2 minutes read -> http://www.bltoolkit.net/doc.linqmodel.ashx
but in short
- extremely linq support
- dml operations (nr 9)
- great performace / bulk support
- great generated sql
- enum support ;-)
- no lazy loading / entity tracking / special magic caching, these things cause problems
- no magic features -> less abstraction -> less leaks -> less troubles -> smaller learning curve
btw nr 3, has attributes tablefunction & tableexpression support table-valued udf, hints, , other around table decorations. can write own extension methods use in linq-statements example
[tableexpression("{0} {1} (tablock)")] public table<t> withtablock<t>() t : class { return _ctx.gettable<t>(this, ((methodinfo)(methodbase.getcurrentmethod())).makegenericmethod(typeof(t))); }
and
using (var db = new testdbmanager()) { var q = p in new model.functions(db).withtablock<parent>() select p; q.tolist(); }
sample dml operation
db.employee .where(e => e.title == "spectre") .set(e => e.title, "commander") .update();
Comments
Post a Comment