Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    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);
    Sruti
    @Su-s
    hi is it possible to give the jsonproperty for property names to the dto in automapper?
    public class BatchModel
    {
    [JsonProperty("Batch Id")] public string BatchId { get; set; }
    [JsonProperty("Processed Date")] public string ProcessedDate { get; set; }
    [JsonProperty("Input Files")] public string Filename { get; set; }
    }
    this is the dto class im using in my code
    public class BatchEntity

    {
    public DateTime BatchId { get; set; }
    public string ProcessedDate { get; set; }
    public string Filename { get; set; }
    }

    this is the entity class

    and im creating mapping like this mappingProfile.CreateMap<BatchEntity, BatchModel>()
    and im using the mapper like this
    _mapper.Map<BatchEntity, BatchModel>(batchEntity)).ToList();
    but im not getting the json property in the response
    is there any mistake in my code
    Sruti
    @Su-s
    im using newtonsoftJson package to get the jsonproperty
    @all please help me that i want the item name with spaces
    Edward Lichtman
    @EdLichtman
    Hiya Sruti. So if i understand properly you're mapping from object a to object b, and then you're serializing object b and not seeing your properties appear?
    Are you sure that the mapping is occurring? If you debug you should see a list of BatchModel. If you expand Batchmodel List do you see your properties as expected?
    Edward Lichtman
    @EdLichtman
    If it maps properly then the issue is with your implementation of Newtonsoft.Json and you'd be better suited asking them for help. That being said i haven't worked in that space in a while but the first thing I'd consider is that since JSON.NET is a traditionally 3rd party package, perhaps you haven't properly configured a custom serializer and JsonProperty might not work out of the box like DataMember does? I'm on my phone so i can't link you but google "how to register actionfilterattribute webapi" and "actionfilterattribute custom serializer". You should be able to piece it together if that is indeed the issue.
    Sruti
    @Su-s

    @EdLichtman mapping is working and can view the output like this

    {
    "batchId": "30-11-2020",
    "processedDate": "01-01-2020 12:00 AM",
    "filename": "batchfile0101.txt"
    }

    but i want to get like this

    {
    "Batch Id": "30-11-2020",
    "Processed Date": "01-01-2020 12:00 AM",
    "Input Files": "batchfile0101.txt"
    }

    sure i will check this out thankypu for the help @EdLichtman
    Edward Lichtman
    @EdLichtman
    Hi. I can take a look in a few
    What version of DotNet are you using?
    Edward Lichtman
    @EdLichtman
    Have you tried JsonPropertyName like dbc suggested in the Stack Overflow topic? depending on the version of DotNet you're using you'll have to consider that
    Sruti
    @Su-s
    @EdLichtman .netcore 3.1
    Sruti
    @Su-s
    it worked @EdLichtman thanks for the support
    Edward Lichtman
    @EdLichtman
    Cheers!
    sephiroth5
    @sephiroth5:matrix.org
    [m]
    Hi every one
    I have a derived class inheriting from a base abstract class and Mapster give me an error "Instances of abstract classes cannot be created"
    so map not work
    Chase Florell
    @ChaseFlorell
    Hey folks, I'm trying to bend AutoMapper to my will, and I'm coming up short.
    When AutoMapper maps the src to the dest and fails, I need fidelity into the src details in order to help bolster my logging.
    I've searched for some kind of "OnError", but couldn't find anything. Then I tried "AfterMap", but it doesn't get his on an exception.
    Can someone give me direction on how to capture the AutoMapperMappingException and also have fidelity into the source object?
    Jan Tesař
    @tesar-tech

    Hi. Just a quick question about ReverseMapping: Is this:

     CreateMap<Routine, RoutineDto>();
     CreateMap<RoutineDto,Routine>();

    same as this:

     CreateMap<Routine, RoutineDto>().ReverseMap();

    or this:

    CreateMap<RoutineDto, Routine>().ReverseMap();

    ???
    I always thought it is, but now I found some cases where it throws different results.

    philipphagen87
    @philipphagen87
    Hello together, sorry for a stupid question but I never used a mapper before... so maybe someone can help a newbe :)
    My Problem is that i want to map the left side to the right one how should i configurate the mapper?
    philipphagen87
    @philipphagen87
    image.png
    JardarM
    @JardarM

    I want map the following:

    CreateMap<IDictionary<string, A>, IDictionary<string, B>>
    
    class A {
        public string Name{get;set;}
    }
    
    class B{
        public string Id{get;set;}
        public string Name{get;set;}
    }

    Where the Id in class is populated from the key of the dictionary.

    My solution is, but is seems like overly complex. Is there a better way?

    CreateMap<IDictionary<string, A>, IDictionary<string, B>>()
                    .ConstructUsing((opt, c) => opt.Select(t =>
                    {
                        var v = c.Mapper.Map<B>(t.Value);
                        v.Id = t.Key;
                        return KeyValuePair.Create(t.Key, v);
                    }).ToDictionary(t => t.Key, k => k.Value))
                    .ForMember("Item", op => op.Ignore()) 
                    .ForMember(src => src.Keys, opt => opt.Ignore())
                    .ForMember(src => src.Values, opt => opt.Ignore());
    ashokgovindaraj
    @ashokgovindaraj
    image.png
    ashokgovindaraj
    @ashokgovindaraj

    Hi, I have upgraded my program from .Net core 3.1 to .Net 6 and also to AutoMapper.Extensions.Microsoft.DependencyInjection 11. My mapping is not working. But which is working on AutoMapper.Extensions.Microsoft.DependencyInjection 7.0.0.

    Error mapping types.

    Mapping types:
    AccessUser -> AccessUserDto
    AEGIS.Models.AccessUser -> IO.Swagger.Model.AccessUserDto

    Type Map configuration:
    AccessUser -> AccessUserDto
    AEGIS.Models.AccessUser -> IO.Swagger.Model.AccessUserDto

    Could you help me on this? Did I miss anything?
    rahul sahay
    @rahulsahay19
    Hi, after upgrading to automapper 11 version, I saw that support for .ForAllOtherMembers(o => o.Ignore()) not available. Is there any other prop replaced this?
    rahul sahay
    @rahulsahay19
    Also, assembly scanning started giving issue in test project public static IMapper getInitializedMapper() => new MapperConfiguration(config => config.AddProfiles(Assembly.GetAssembly(typeof(IOrchestrationAction)))).CreateMapper();
    TestDataProvider.cs(35, 110): [CS1503] Argument 1: cannot convert from 'System.Reflection.Assembly' to 'System.Collections.Generic.IEnumerable<AutoMapper.Profile>'
    Diaz1515
    @Diaz1515
    hi everyone, could you help me to configure Automapper https://stackoverflow.com/questions/73179436/how-to-use-automapper-with-included-linq