Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Kevin Sigmund
    @ksigmund
    But for some reason, AutoMapper is trying to map the resolver: System.InvalidCastException : Unable to cast object of type 'Newgistics.Fulfillment.AutoStore.Synq.Client.Mappings.ProductImagePathResolver' to type 'Newgistics.Fulfillment.AutoStore.Common.Mappings.NullableValueResolver'.
    Kevin Sigmund
    @ksigmund
    I ended up just using constructor-injection into the Profile and then passing that into the Resolver there. Still, not sure why I'm seeing the behavior I described.
    Maxime Dubois
    @maximedubois
    how can I create mapping for the source being a serialized json array to a destination of a list of an object?
    Shayne van Asperen
    @shaynevanasperen
    @maximedubois Mapper.CreateMap<string, List<MyObject>>() with your own custom value resolver
    Victorio Berra
    @VictorioBerra
    Is there a way to specify a global base map without having to include every time?
    For example, I have IAuditable and IAuditableViewModel. Some of my viewmodels have it, some dont. In my profiles I am having to Include<IAuditable, IAuditableViewModel>()every time
    atresnjo
    @atresnjo
    I have two models, one has a List<Guid> collection and one has a List<Dto> collection. When mapping I'd like to resolve those Guids to Dtos but IValueResolver doesn't support async which I need to call certain methods to resolve the objects, how can I accomplish this with AutoMapper?
    Thanks! :)
    Victorio Berra
    @VictorioBerra
    ForAllMaps is not running for me. I put throw new NotImplemenetEx... My assert config blows up before that throw ever happens. Shouldnt all profiles be loaded before this happens?
    Looks like order matters. If I put ForAllMaprs directly on the config in AddAutoMapper it works.
    Teo Chai Huat
    @chteoeducloudmy_gitlab
    Hi All, not sure what I did wrong, my nullable object always reset to default value. how do I configure automapper to ignore/skip null object?
    https://stackoverflow.com/questions/55137405/how-to-set-automapper-ignore-null
    Thanks.
    Dino
    @DinoSourcesRex

    Guys I need some help.

    I want to set a destination object to null if certain properties in the source are not present. How would that look?

    Dino
    @DinoSourcesRex

    Another question - is it possible to use AutoMapper to convert another member if it is a subproperty of another mapping?

    Source_2 has a property called Destination_1

    Example:

    CreateMap<Source_1, Destination_1>();
    
    CreateMap<Source_2, Destination_2>()
       .ForMember(d => d.Destination_1, o => o.MapFrom(s => map into <Destination_1> using the first mapping));
    Jack Herring
    @JackHerring
    Unsure if it is bad etiquette here to post links to SO questions but I am stuck and in need of help! https://stackoverflow.com/questions/56258652/automapper-global-configuration-convert-null-array-property-to-empty-array-by does anyone know how to configure default array conversion behaviour when the source array is null? AutoMapper is exploding because int[] doesn't have a no-arg ctor
    Bob Meijwaard
    @bob_meijwaard_twitter
    Mapper.Initialize(cfg => { cfg.AddProfile<CoreProfile>(); }); So as I just updated to v8.1.1 and VS now tells me that the static API is obsolute and that I have to use DI. Why? I don't want that, please do not obsolute the static API.
    TheSoulsKing
    @TheSoulsKing
    You should do the following:
    var cfg = new MapperConfigurationExpression();
    cfg.CreateMap<Domain.Entities.OrderRoot, IApp.DTO.OrderRoot>();
    Mapper.Initialize(cfg);
    lrushl
    @lrushl
    @DinoSourcesRex, if I understand you requirement propertly then you may try something like this
    cfg.CreateMap<Source1, Destination1>();
    cfg.CreateMap<Source2, Destination1>()
          .IncludeMembers(x => x.PropOfSource1Type);
    
    class Source2
    {
      Source1 PropOfSource1Type {get; set;}
      //… other props
    }
    spydacarnage
    @spydacarnage
    Hi,
    I've encountered an issue which seems to have been raised previously (AutoMapper/AutoMapper#2745) but with no resolution, and the workaround mentioned has a flaw when the destination object has more than one constructor.
    I've looked at the source code in order to type to identify a solution, but it seems that during the MapDestinationCtorToSource method, the only access to the ForCtor methods in via:
    options._typeMapConfigs[].CtorParamConfigurations[], but due to the generic abstraction layers involved, I can't fathom how to do the checking required.
    Any assistance would be appreciated...
    James Webster
    @jimmcslim
    Is it possible to customise the mapping of a class -> ExpandoObject? I have an IEnumerable<SomeClass> that I can map to IEnumerable<ExpandoObject> just fine, but I want to explictly override some of the dynamically generated mapping, (e.g. some properties on SomeClass should be given a different name on the ExpandoObject, some should have their type converted, but most of them should be mapped automatically).
    If I just call _mapper.Map<IEnumerable<ExpandoObject>>(anEnumerableOfMyClass) then everything is mapped onto the enumerable of ExpandoObject.
    James Webster
    @jimmcslim
    If I configure a map via CreateMap<SomeClass, ExpandoObject>() then I get a list of empty ExpandoObjects. Is there a way to tell CreateMap to do the default mapping (I have tried various combinations of .ForAllMembers() but there doesn't appear to be a way to say - just do the default behaviour... which I would then override with .ForMember()
    James Webster
    @jimmcslim
    I think the problem I have here is that mapping is generally focused on the members of the destination. In this case, the destination has no explicit members. But there doesn't seem to be a way to override the default behaviour when mapping TO dynamic.
    enif.lee
    @enif-lee
    Hello there, Are there anyone who know what encoding type of test code files(AutoMapper.UnitTests.Internationalization.When_mapping_a_source_with_non_english_property_names, AutoMapper.UnitTests.Tests.StubNamingConvention)? I couldn't build and test automapper solution, My jetbrains rider can't recognize encoding type of this file.
    Osama AbuSitta
    @OsamaAbuSitta
    hello there , I am download automapper source code and trying to build it ,
    when run the psake.cmd I got this error "C:\Users\o.abusitta.nuget\packages\microsoft.dotnet.apicompat\1.0.0-beta.19423.1\build\Microsoft.DotNet.ApiCompat.targets(96,5): error : ApiCompat failed for 'D:\AutoMapper-master\AutoMapper-master\src\AutoMapper\bin\Debug\netstandard2.0\AutoMapper.dll' [D:\AutoMapper-master\AutoMapper-master\src\AutoMapper\AutoMapper.csproj]"
    and when I build it i got "Error ApiCompat failed for '"
    There is any guideline to build the solution
    Osama AbuSitta
    @OsamaAbuSitta
    ?!!!!!!!!!
    Edward Lichtman
    @EdLichtman
    I'm looking for a "<Any,Any>" method of mapping. I can't seem to find one and was wondering if there is a "best-practices" reason there isn't one, and does anyone have a workaround like a "CatchAllMapper" implementation?
    mdrokz
    @mdrokz
    hello
    Sander Geerts
    @Devqon

    Hi all, how would I configure Automapper in a Profile to do a mapping which changes the object struture? e.g.:

    ParentObjectA
        ChildObjectA
            DeepObjectA
        ChildObjectB
            DeepObjectA
        ChildObjectC
            DeepObjectB

    Should Become

    ParentObject
        DeepObjectA
            List<ChildObject> // ChildObject A and B
        DeepObjectB
            List<ChildObject> // ChildObject C
    yousuf14
    @yousuf14
    this.CreateMap<Data.Task.Task, POCO.Task>() .ForMember(d => d.User, o => o.MapFrom(m => m.UserTaskAssignment.FirstOrDefault().User.Name))
    I am using automapper to map my data object to poco. User property is not being populated even though I added mapping. Rest of the map works.
    yousuf14
    @yousuf14
    I tried .AfterMap((o,d) => d.User = o.UserTaskAssignment.FirstOrDefault()?.User.Name); as well. Did not work.
    Daxesh Vora
    @DaxeshHVora_twitter

    I am trying to map Automapper to map string to datetime and datetime? so using below method

    "CreateMap<DateTime?, string>().ConvertUsing(opt => opt.ConvertDateTimeToString("dd/MM/yyyy"));
    CreateMap<string, DateTime?>().ConvertUsing(opt => opt.ConvertStringToNullableDateTime("dd/MM/yyyy"));
    CreateMap<DateTime, string>().ConvertUsing(opt => opt.Date.ConvertDateTimeToString("dd/MM/yyyy"));
    CreateMap<string, DateTime>().ConvertUsing(opt => opt.ConvertStringToDateTime("dd/MM/yyyy"));"

    But its giving below error

    InvalidCastException: Unable to cast object of type 'System.Func4[System.String,System.Nullable1[System.DateTime],AutoMapper.ResolutionContext,System.DateTime]' to type 'System.Func4[System.String,System.Nullable1[System.DateTime],AutoMapper.ResolutionContext,System.Nullable`1[System.DateTime]]'.
    AutoMapper.MapperConfiguration.GetMapperFunc<TSource, TDestination>(MapRequest mapRequest)

    AutoMapperMappingException: Error mapping types.

    yousufhossain
    @yousufhossain
    Do you need an automapper map for DateTime? to string or string to DateTime?. I think if you are mapping object property you would have code there to cast it. String to DateTime is tricky. Need to use DateTime.TryParse.
    Daxesh Vora
    @DaxeshHVora_twitter
    I know I can do for each object property. But there were around 20 datetime property and so I wanted to manage it using less code instead of typing for all 20 properties. Finally I understood the issue, it was not able to understand when converting from string to datetime to use conversion of datetime or datetime?. On removing one function of string datetime, it worked fine.
    clintsinger
    @clintsinger
    Hi, I have run into an issue that has got me stumped. I have posted the question on StackOverflow if there is anyone here who might be able to help me :) https://stackoverflow.com/questions/61721294/in-automapper-how-does-one-project-from-an-abstract-base-class-to-an-interface
    I am running into an error stating that my interface doesn't have a default constructor (obviously). I have read all of the documentation and reviewed the unit tests and am really stuck.
    clintsinger
    @clintsinger
    Well it looks like it isn't possible, which is a shame. The response from issue AutoMapper/AutoMapper#3293 is that it is due to a limitation of the EF provider. But in this case the EF provider does allow it. I assume this is a common issue with people and I am wondering what workarounds people have devised?
    Sami Al Khatib
    @alsami
    Just out of curiosity, why would you map entities to interfaces?
    pm64
    @pm64
    Anyone awake? I'm trying to map an object with a T[] property to an object with an ObservableCollection<T> getter-only property, where both properties have the same name. The property isn't mapped because the destination is getter-only. But if I reluctantly add a setter to the ObservableCollection property, Automapper throws an ArgumentException "Argument types do not match". What gives?
    pm64
    @pm64
    I get this same error even if I manually map the member using a custom resolver :\
    pm64
    @pm64
    I found a workaround: replacing this call
     var foos = mapper.ProjectTo<FooModel>(myFoos.AsQueryable());
    with this:
     var foos = myFoos.Select(x => mapper.Map<FooModel>(x));
    Not really sure why the result is different? Maybe I'm misunderstanding ProjectTo()?
    Kevin Hernández Rostrán
    @kevinah95

    Hello everyone. I have a problem
    I have this map

    CreateMap<RemoFlatProcedureDTO, string>()
                    .ForMember(destination => destination, option => option.MapFrom(source => source.procedureTemplate.code));

    but i get this message:

    Automapper Custom configuration for members is only supported for top-level individual members on a type

    Have you some suggestions? How can I map to plain string value?
    Kevin Hernández Rostrán
    @kevinah95
    I got it... Thank you!
    With:
    CreateMap<RemoFlatProcedureDTO, string>()
                                    .ConstructUsing(source => source.procedureTemplate.code);