Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    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);
    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.