asp.net mvc - Entity Framework 4 POCO's and AutoMapper -


i have been working on new mvc application utilizies ef4, poco domain objects , repository <--> service layer.

i see lot of talk using automapper map ef4 classes dto view models. under impression rid of tightly bound ef4 classes. question since using poco classes, can't use in view models? or there still need automapper?

the argument "poco's" domain models, , view's shouldn't concerned domain models.

think way - data validation, if want data annotations, have put them on poco's - input validation (this field required, etc) isn't domain concern, it's ui concern - hence use of viewmodels data annotations , automapper.

of course, it's not cut , dry, it's matter of preference.

i use mvc/ef4/poco/automapper/service layer , never bind poco's - use viewmodel per view.

this way, have level of consistency:

  • all view's have viewmodel
  • poco's have nothing business/domain logic
  • viewmodel's have basic input validation
  • they mapped poco's, invoke domain/business validation

**edit - in response comments: **

do repositories return iqueryable? if so, how handle context? mean repositories implement idisposable , dispose of them in controllers?

yes - repositories return iqueryable<t>, t aggregate root. repositories passed unit of work (which implements idisposable). unit of work wrapper ef4 context. structuremap (di container) responsible lifetime of components (including uow - aka context). new uow per http request , dispose when it's finished. "service" calls methods on iqueryable repository , returns collections (e.g materializes query before being passed controller).

where do mapping at? do in controller?

up you. personally, create static "bootstrapper" class has single method, e.g "configure". call once in application_start event (global.asax). technique decribed here.

good luck!


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -