Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Custom Templates> @Otis: update from hierarchical dto to entity
 

Pages: 1
Custom Templates
@Otis: update from hierarchical dto to entity
Page:1/1 

  Print all messages in this thread  
Poster Message
Puser
User



Location:

Joined on:
20-Sep-2012 14:40:04
Posted:
138 posts
# Posted on: 07-Dec-2017 14:56:32.  
@Otis:

hi, i've created a template which creates an automapper profile for each root dto. This is a simple and naive implementation which relies on properties to have the same name (although these can be created). Only the navigationproperties to multiple children can have another name.

It also doesnt take into account any inherited subtypes, to keep things simple.
It can add, update and delete (sub)children with help of Automapper.Collection and make use of the simple EqualityComparison which looks for equality of the Id fields. This is naive because I only take the first identifying field (skipping the foreign key). When needed this can be extended. I dont use it.

And... the template itself is still very dirty for it has been copied from rootDerivedElementPersistenceInclude and not cleaned. Wink

It adds the profiles into the persistence project for that already know both entity and dto.
you can simple scan the persistence project(s) from automapper.

For your idea, an example, maybe you are working towards something like this...

Code:
//------------------------------------------------------------------------------
// <auto-generated>This code was generated by LLBLGen Pro v5.3.</auto-generated>
//------------------------------------------------------------------------------
using AutoMapper;
using AutoMapper.EquivalencyExpression;

namespace VA.Pac.DomainData.Aggregates.Mapping
{
    /// <summary>class for automapping projecting instances of VA.Pac.DomainData.Aggregates.DtoClasses.RoyaltyContractRoot to the entity model.</summary>
    public class RoyaltyContractRootMappingProfile : Profile
    {
        public RoyaltyContractRootMappingProfile()
        {

            CreateMap<VA.Pac.DomainData.Aggregates.DtoClasses.RoyaltyContractRoot, VA.Pac.DomainData.EntityClasses.RoyaltyContractEntity>()
                        .ForMember(d => d.RoyaltyContractExploitatieGroepen, o => o.MapFrom(s => s.ExploitatieGroepen))
                        .ForMember(d => d.RoyaltyContractRechtTypes, o => o.MapFrom(s => s.RechtTypes))
                        .ForMember(d => d.RoyaltyContractRelaties, o => o.MapFrom(s => s.Relaties))
                        .ForMember(d => d.RoyaltyVoorschotten, o => o.MapFrom(s => s.Voorschotten));
            CreateMap<VA.Pac.DomainData.Aggregates.DtoClasses.RoyaltyContractRootTypes.ExploitatieGroep, VA.Pac.DomainData.EntityClasses.RoyaltyContractExploitatieGroepEntity>()
                .EqualityComparison((dto, e) => dto.RoyaltyContractExploitatieGroepId == e.RoyaltyContractExploitatieGroepId)
                .ForMember(d => d.RoyaltyContractExploitatieGroepUitgaven, o => o.MapFrom(s => s.Uitgaven))
                .ForMember(d => d.RoyaltyContractExploitatieGroepVerkoopsoorten, o => o.MapFrom(s => s.Verkoopsoorten))
                .ForMember(d => d.RoyaltyContractExploitatieGroepUitgaveVerkoopStanden, o => o.MapFrom(s => s.VerkoopStanden));
            CreateMap<VA.Pac.DomainData.Aggregates.DtoClasses.RoyaltyContractRootTypes.ExploitatieGroepTypes.Uitgave, VA.Pac.DomainData.EntityClasses.RoyaltyContractExploitatieGroepUitgaveEntity>()
                .EqualityComparison((dto, e) => dto.RoyaltyContractExploitatieGroepUitgaveId == e.RoyaltyContractExploitatieGroepUitgaveId);
            CreateMap<VA.Pac.DomainData.Aggregates.DtoClasses.RoyaltyContractRootTypes.ExploitatieGroepTypes.Verkoopsoort, VA.Pac.DomainData.EntityClasses.RoyaltyContractExploitatieGroepVerkoopsoortEntity>()
                .EqualityComparison((dto, e) => dto.RoyaltyContractExploitatieGroepVerkoopsoortId == e.RoyaltyContractExploitatieGroepVerkoopsoortId);
            CreateMap<VA.Pac.DomainData.Aggregates.DtoClasses.RoyaltyContractRootTypes.ExploitatieGroepTypes.VerkoopStand, VA.Pac.DomainData.EntityClasses.RoyaltyContractExploitatieGroepUitgaveVerkoopStandEntity>()
                .EqualityComparison((dto, e) => dto.RoyaltyContractExploitatieGroepUitgaveVerkoopStandId == e.RoyaltyContractExploitatieGroepUitgaveVerkoopStandId);
            CreateMap<VA.Pac.DomainData.Aggregates.DtoClasses.RoyaltyContractRootTypes.RechtType, VA.Pac.DomainData.EntityClasses.RoyaltyContractRechtTypeEntity>()
                .EqualityComparison((dto, e) => dto.RoyaltyContractRechtTypeId == e.RoyaltyContractRechtTypeId);
            CreateMap<VA.Pac.DomainData.Aggregates.DtoClasses.RoyaltyContractRootTypes.Relatie, VA.Pac.DomainData.EntityClasses.RoyaltyContractRelatieEntity>()
                .EqualityComparison((dto, e) => dto.RelatieId == e.RelatieId);
            CreateMap<VA.Pac.DomainData.Aggregates.DtoClasses.RoyaltyContractRootTypes.Voorschot, VA.Pac.DomainData.EntityClasses.RoyaltyVoorschotEntity>()
                .EqualityComparison((dto, e) => dto.RoyaltyVoorschotId == e.RoyaltyVoorschotId)
                .ForMember(d => d.Betalingen, o => o.MapFrom(s => s.Betalingen));
            CreateMap<VA.Pac.DomainData.Aggregates.DtoClasses.RoyaltyContractRootTypes.VoorschotTypes.Betalingen, VA.Pac.DomainData.EntityClasses.RoyaltyBetalingEntity>()
                .EqualityComparison((dto, e) => dto.BetalingId == e.BetalingId);
            ;
        }
    }
}


  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37313 posts
# Posted on: 08-Dec-2017 17:26:25.  
Cool Regular Smiley

No we're not looking at generating code for automapper, as I didn't want to enforce that dependency on people, mainly also because the design for fetching doesn't need automapper and for updates we focus only on the main entity/dto (as with the denormalized fields and other things, it's not really feasible to update related entities as well).


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.