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:
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.