AutoMapper, Don't Overwrite Existing Value if Not Present

AutoMapper, Don't Overwrite Existing Value if Not Present

Content Index :

AutoMapper, Don't Overwrite Existing Value if Not Present
Tag : chash , By : toma
Date : November 26 2020, 03:04 PM

like below fixes the issue If I am not mistaken you can pass the destination as argument to call that specific functionality through the overload:
test1 = _mapper.Map(test2, test1 );

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to force Automapper to overwrite array property?

Tag : chash , By : user86493
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I am using Automapper in my project to map business entities to DTO. , I solved my problem by downgrading to version 2.0.0.

Overwrite Existing Mapping with Automapper

Tag : chash , By : Cube_Zombie
Date : March 29 2020, 07:55 AM
may help you . using Automapper version 5.2.0, your syntax should be as below. You should use ResolveUsing instead of MapFrom and swith-case should be within curly brackets. you dont have to use any Mapper.Initialize(). I tested this code and it works for me. I hope that it helps for you also. Cheers.
Similar question asked here. see the answer from Mrchief
   var config = new MapperConfiguration(cfg =>
        Mapper.CreateMap<Report, ReportViewModel>()
            .ForMember(src => src.Value, 
                       dest => dest.ResolveUsing(r => {
                                case ReportingPeriod.Daily:
                                    return r.Day.Value;
                                case ReportingPeriod.Weekly:
                                    return r.Week.Value;
                                case ReportingPeriod.Monthly:
                                    return r.Month.Value;
                                case default:
                                    return null;

       var mapper = config.CreateMapper();

Array merge with same key's dont' overwrite

Tag : php , By : Ike
Date : March 29 2020, 07:55 AM
may help you .
Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array.

Automapper Mapping Objects of Same Type - Overwrite Bools

Tag : chash , By : meehan
Date : March 29 2020, 07:55 AM
it helps some times If you're implementing some logic on mapping, better do it on each member explicitly.
But if you really want to do it via AutoMapper magic, you can add this condition:
options.Condition((source, destination, member) => (member as bool?) != false);

Modify xls to look for any existing attribute, if present don't overwrite w/ xsi:nil="true"

Tag : xslt , By : ack
Date : March 29 2020, 07:55 AM
this will help You just need to add a check for attributes in your template match too...
<xsl:template match="*[not(text()) and not(@*)]">
    <xsl:attribute name="xsi:nil">true</xsl:attribute>
<xsl:template match="*[not(text()) and not(*) and not(@*)]">
Related Posts Related QUESTIONS :
  • How to convert API Json response to C# Array?
  • Blazor Textfield Oninput User Typing Delay
  • Performing both layout and render transform results in wrong output
  • uwp beforetextchanged cursor moving in front of text
  • How to keep duplicates from a string[] exclude words from a List and print them out
  • .Net Core Strings.Asc/Mid/Chr/Len missing even after importing Microsoft.VisualBasic
  • How to return to previous search page without being asked to Confirm Form Re-submission and keeping the results on ASP.N
  • How set a identity scaffolding item/page how initial page in asp.net MVC core?
  • LINQ isn't calling Dispose on my IEnumerator when using Union and Select, expected behavior or bug?
  • What is "ByteArray.uncompress()" in AS3 equivalent to in C#?
  • Getting a specific letter from a string variable for my simple guessing game for clues
  • Send an email with Outlook without a subject --- dialog box issue
  • passing List<MyModel> from my controller in the "WebInterfaceProject" to the processor method in "D
  • How to convert Word document created from template by OpenXML into MemoryStream?
  • How can I make a single slider that changes the color of an object?
  • Remap JSON parameter in c#
  • What is the difference between "this ref" and "ref this" when talking about C# 7.2 ref extension met
  • Convert OpenSSL encryption into native C#
  • Accessing Properties in Razor Pages
  • How to get SOAP element value
  • Projection after Group
  • C# error cannot convert sytem.text.regularexpressions.match to string
  • Issues with Save/Load System in a Text Based Adventure game made with ScriptableObjects in Unity
  • VS2019 MSBuild.exe - ASP .Net MVC project fails to publish when using PublishProfile, but works when using OutDir parame
  • Does <pages validateRequest="false" /> in Web.config still matter?
  • How to send new request to redirect URL with new access token
  • Attempt to invoke virtual method on a null object reference Xamarin LockScreen
  • "The attribute names could not be inferred from bind attribute 'bind-value'" exception in Blazor
  • How to fix ''System.ArgumentException" in c#?
  • C#. Ref returning delegate for ref extension method
  • Swashbuckle Swagger generate an actual guid
  • Trying to make thousands of database calls simultaneously - they stack instead of running concurently
  • run mstest from cmd using testcontainer
  • How to make M:N (many-to-many) relationship where both M and N are the same entities?
  • Consume COM DLL from multiple clients
  • Convert json string response representing UCHAR array to Byte array
  • Why does this LinqPad program produce different results on the second run?
  • ServiceStack how to use MaxLoginAttempts feature
  • What does "late-bound access to the destination object" mean?
  • How to load appsettings.json inside a Static class based on deploy environment so that I can use in other class librarie
  • dynamically add images to view
  • Are static extension methods on User object safe?
  • Process thousands of database calls simultaneously
  • Trying to decrypt a string with public key(not private) using bouncycastle in .net
  • How to retrieve the name of an usb device
  • Query many-to-many related data using Entity Framework Core
  • ASP.NET MVC : how to find the view from a controller?
  • Inconsistent behaviour using Entity Framework for ASP.NET MVC app vs windows service
  • AutoFixture Customize vs Build
  • How to change textbox location at the click of a mouse in live mode?
  • How can I deserialize a XML file without defining the parent node?
  • asp.net core how decrease class coupling
  • ASP.NET Core Razor Pages Routing With parameters
  • String Escaping With $ Interpolation and @ Encoding
  • ConfigurationManager in ASP.NET WebAPI tested with HttpServer
  • Top down shooting in Unity 2D don't work as I want it to
  • Use own redirectUri when the Authentication expires
  • Using "foreach" in string array c#
  • "Object reference not set to an instance of an object" for create multiply models on one view
  • Get data passed trought pushAsync
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com