Back to list
Views:   8.3K
Replies:  1
Archived

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)
        BusinessLayer
        PresenterLayer
        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..

     Thanks.

      Best Regards.
 
 

   
Volkan Genç, May 11, 2012
Reply 1
Volkan,

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 AutoMapper.org.

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     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas