c# - automapper optimization mapping (model to view model -> get latest version) -
i trying optimize part of code:
mapper.createmap<document, documentviewmodel>() .formember(g => g.id, map => map.mapfrom(d => d.documentversion.where(v => v.version == d.documentversion.select(s => s.version).max()).orderbydescending(s => s.subversion).first().id)) .formember(g => g.idrootdocument, map => map.mapfrom(d => d.id)) .formember(g => g.certyficatetype, map => map.mapfrom(d => d.documentversion.where(v => v.version == d.documentversion.select(s => s.version).max()).orderbydescending(s => s.subversion).first().certyficatetype))
i'm using automapper, , i'm trying optimize part of code
in part i'm trying mapping object document documentviewmodel, in complex model, source data latest document version:
d => d.documentversion.where(v => v.version == d.documentversion.select(s => s.version).max()).orderbydescending(s => s.subversion).first().myproportyx
could offer example or suggestion how approach optimization in situation?
d => d.documentversion.where(v => v.version == d.documentversion.select(s => s.version).max()).orderbydescending(s => s.subversion).first().myproporty
you iterating quite few times here, may consider doing like:
d.documentversion.orderbydescending(v => v.version).thenbydescending(v => v.subversion).first().myproperty
to reduce number of iterations , top version/subversion.
Comments
Post a Comment