Back to list
Views:   8.3K
Replies:  1

E.F 4.1 CodeFirst,Generic Repository Pattern,UoW,MVP

 Hİ ,

    I developed a windows form project with using  E.F 4.1 CodeFirst model, Generic RepositoryPattern, Unit Of Work and MVP.
    I made 4 layers which are like below.

        DataAccessLayer (Entities like tblCustomers, tblUsers,  Repositories like CustomerRepository,UserRepository)
        UI -->Windows Forms.

    My Problem is carrying exceptions beetween the layers and  carriying the data between the layers. I made a DTO datatransfer objects which names like  CustomerDto, UserDto.
     When I query  generic repository      forexample      CustomerRepository<tblCustomers>  it returns tblCustomer type data , but i want to fill CustomerDto class , so i have to write query business layer, But  i have to this job in  Data Access Layer  ,  I dont want to carry tblCustomer entities between the layers.

     Is it correct what i have done, if wrong how can i do..


      Best Regards.

Volkan Genç, May 11, 2012
Reply 1

I've done similar things, and my suggestions are:
  1. AutoMapper - use this component to automatically map your DTOs to your business objects
  2. Service Layer - I have a service layer for this type of thing.  Gather the objects or collection from your repository, then in the service layer you can map the objects together.

You can find out about AutoMapper at

I hope this helps.

King Wilder

// First configure the mapping...
AutoMapper.Mapper.CreateMap<Source.Entity.Categories, Destination.CategoriesDto>();

// Then map the objects and return the newly mapped object.
CategoryDto dto = AutoMapper.Mapper.Map<Source.Entity.Categories, Destination.CategoriesDto>(entity);

King Wilder, Jun 01, 2012
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.