Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Mihai
    @mihaivader
    hey, are you referring to the Map(s, d, context) method? because it works fine in my case
    Steven Liekens
    @StevenLiekens
    me? no
    Eric
    @sliceofbytes
    @StevenLiekens , you are correct thanks for correctng me
    Steven Liekens
    @StevenLiekens
    np thanks for trying to help
    Pablo Montilla
    @rokleM
    Hello there, I'm not sure if this warrants an issue post or if I just need to characterize better my problem. I'm getting a NullRef on SourceToDestinationNameMapperAttributesMember.cs sometimes while running my code. I you see line 18, when array.Length == 0 line 20 will always throw...any ideas how I can fix this problem?
    Brian Donahue
    @briandonahue
    I'm trying to map a dynamic/ExpandoObject to a class of mine, and seeing some behavior I don't understand. When I use CreateMissingTypeMaps it executes the mapping, but crashes because there are some mismatched types (string > decimal, etc). I need to do some custom mapping. So I tried to create my own maps using CreateMap<dynamic, MyType>() or CreateMap<ExpandoObject, MyType>() but those didn't work. The Map call returns an empty object (default values). Is this possible? Next step is to try converting the ExpandoObject to IDictionary<string, object> and create a custom mapping for that.
    Alexander Carls
    @alexandercarls

    I am trying to debug why my AutoMapper map, does not leverage joins with EF Core. I created a slim down query

            await db
              .Moves
              .Select(m => new Move {
                Id = m.Id,
                CommandSegments = m.CommandSegments.Select(c => c.Segment),
                Notes = m.Notes.Select(n => n.Text)
              })
              .ToListAsync(token);

    This results in three queries for Moves, Notes and CommandSegments, while I would rather have just one.
    Doesn anyone have an idea why? I am using the Postgres adapter.

    rmindel
    @rmindel
    Question -Does the mapper work using reflection every map call? or are you compiling IL code at run time for each mapping profile to make the performance better?
    Sampath
    @sampathdr
    Hi All, I am getting "Value cannot be null. Parameter name: querySource" exception when try to use Automapper
    It is coming from this member mapping
    .ForMember(p => p.Region, opt => opt.MapFrom(p => p.RegAddress.Country.Region != null ? p.RegAddress.Country.Region : p.Nationality.Region))
    If I use only one mapping without using conditional mapping, it is working
    for e.g. .ForMember(p => p.Region, opt => opt.MapFrom(p => p.Nationality.Region)) or .ForMember(p => p.Region, opt => opt.MapFrom(p => p.RegAddress.Country.Region )) working without any issue
    JonLopezGarcia
    @JonLopezGarcia
    Are you trying to map or project an IQueryable? Can you provide the code of the call ?
    Sampath
    @sampathdr
    @JonLopezGarcia I am trying to Project from IQueryable
    var pendingRegs = _worker.Repository<UserRegistration>().All.Where(q => q.Status.Name == UserRegistrationStatus.Pending).ProjectTo<PendingClientModel>().ToList();
    Kevin Sigmund
    @ksigmund
    Hi, I'm having an issue when trying to configure a test that uses a value resolver:
    AutoMapper.Mapper.Initialize(cfg =>
                {
    
                    var config = Substitute.For<IConfiguration>();
                    config[nameof(BaseUrl)].Returns(BaseUrl);
                    cfg.ConstructServicesUsing(c => new ProductImagePathResolver(config));
                    cfg.AddProfiles(Assembly.GetAssembly(typeof(MessageHeaderProfile)));
                });
    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.