Quantcast
Channel: URF - Unit of Work & (extensible/generic) Repositories Framework
Viewing all articles
Browse latest Browse all 1539

New Post: How to add the project() (mapper) option to this framework to extend the repositories queries

$
0
0
I Initially started using AutoMapper to "autogen" my DTO's or ViewModels, however, something you should be aware of in using AutoMapper for DAL ccode - http://www.devtrends.co.uk/blog/stop-using-automapper-in-your-data-access-code.

I have since switched to the tried and tested way of just doing it yourself with projection. Essentially, create DTO's/ViewModel classes for each of your exposed entities, using projection:
            var results = odataQueryOptions.ApplyTo(_repository
                .ODataQueryable()
                .Where(u => u.UserId == userId)
                .OrderBy(o => o.WebsiteName)).Cast<Website>()
                .Select(s => new ProjectEditorDTO()
                {
                    // projection
                    WebsiteGUID = s.WebsiteGuid,
                    WebsiteName = s.WebsiteName,
                    WebsiteNotes = s.WebsiteNotes,
                    DefaultContentType = new DefaulContentType
                        {
                            ContentTypeId = s.ContentType.ContentTypeId,
                            Description = s.ContentType.Description
                        }
                });
This code resides in an OData ProjectEditor class, and configured in WebApiConfig as follows:
             modelBuilder.EntitySet<ProjectEditorDTO>("ProjectEditor"); 
Hope that is of some assistance.

Viewing all articles
Browse latest Browse all 1539

Trending Articles