logo
down
shadow

Automapper Sub Property Mapping


Automapper Sub Property Mapping

By : CH127001
Date : October 19 2020, 08:10 PM
With these it helps To create one collection from many you can use SelectMany extension method. With this method and the following configuration AutoMapper will create PersonDto from PersonEntity.
code :
Mapper.Initialize(cfg => 
{
    cfg.CreateMap<GradeEntity, GradeDTO>()
        .ForMember(dto => dto.GradeId, x => x.MapFrom(g => g.Id))
        .ForMember(dto => dto.OutcomeId, x => x.MapFrom(g => g.Outcome.Id));

    cfg.CreateMap<PersonEntity, PersonDTO>()
        .ForMember(dto => dto.PersonId, x => x.MapFrom(p => p.Id))
        .ForMember(dto => dto.Grades, x => x.MapFrom(p => p.Outcomes.SelectMany(o => o.Grades)));
});


Share : facebook icon twitter icon
Automapper, mapping single destination property as a concatenation of multiple source property

Automapper, mapping single destination property as a concatenation of multiple source property


By : user3902481
Date : March 29 2020, 07:55 AM
will help you One possible way to achieve this is to create a map that uses a specific method for this conversion. The map creation would be:
code :
Mapper.CreateMap<EmailViewModel, Email>()
    .ForMember(e => e.EmailRecipient, opt => opt.MapFrom(v => JoinRecipients(v)));
private ICollection<EmailRecipient> JoinRecipients(EmailViewModel viewModel) {
    List<EmailRecipient> result = new List<EmailRecipient>();
    foreach (var toRecipient in viewModel.To) {
        result.Add(new EmailRecipient {
            RecipientEmailTypeId = 1, 
            RecipientEmailAddress = toRecipient.RecipientEmailAddress
        });
    }

    foreach (var ccRecipient in viewModel.Cc) {
        result.Add(new EmailRecipient {
            RecipientEmailTypeId = 2,
            RecipientEmailAddress = ccRecipient.RecipientEmailAddress
        });
    }

    return result;
}
Automapper mapping property unexpectedly by partial property name match

Automapper mapping property unexpectedly by partial property name match


By : brodie brenna
Date : March 29 2020, 07:55 AM
I wish this help you You are triggering AutoMapper's flattening feature. Frome the documentation:
code :
public class Order
{
    public Customer Customer { get; set; }
}

public class Customer
{
    public string Name { get; set; }
}

public class OrderDto
{
    public string CustomerName { get; set; }
    public decimal Total { get; set; }
}

Mapper.CreateMap<Order, OrderDto>();

var order = new Order
{
    Customer = new Customer
    {
        Name = "John Doe"
    }
};

OrderDto dto = Mapper.Map<Order, OrderDto>(order);
AutoMapper not mapping sub property

AutoMapper not mapping sub property


By : kldp
Date : March 29 2020, 07:55 AM
like below fixes the issue Did not figure out the root cause of the issue, but found a fix.
Changed the MemberDto property Dependents name to Dependentss and it worked. Changing it back breaks it again. I should add there is no other Dependents property on either object.
Keep property of source object to destination property when mapping objects using AutoMapper Map function

Keep property of source object to destination property when mapping objects using AutoMapper Map function


By : Zeon
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I want to map most properties of the current object (this a FinancialBase instance) to another object (the 'destination' object, the schedule, an instance of a Schedule class). However, I need to keep a small set of the destination's properties. , I'd just use mapping to an existing object:
code :
var existingSchedule = new Schedule()
{
    Id = 12,
    ParentId = 34,
    ScheduleNo = 56,
    SchName = "Foo",
};

var schedule = mapper.Map(this, existingSchedule);
var config = new MapperConfiguration(
    cfg => cfg.CreateMap<FinancialBase, Schedule>()
        .ForMember(d => d.Id, opt => opt.Ignore())
        .ForMember(d => d.ParentId, opt => opt.Ignore())
        .ForMember(d => d.ScheduleNo, opt => opt.Ignore())
        .ForMember(d => d.SchName, opt => opt.Ignore()));
automapper - ignore mapping if property type is different with same property name - C#

automapper - ignore mapping if property type is different with same property name - C#


By : Tony mxus
Date : March 29 2020, 07:55 AM
wish of those help How can I ignore mapping if property type is different with same property name? By default it's throwing error. , You should use ignore for properties that should be ignored:
Related Posts Related Posts :
  • Headless Firefox in Selenium C#
  • How do I start a .exe with a json string as parameter correctly?
  • StreamContent not loaded to the end
  • HAP parses formatting in HTML documents
  • repeat and count a loop in an unordered sequence in C#
  • Redundant Casting in Visual studio
  • Lost references in Visual Studio 2017 solution
  • Is there a way to add two numbers using a private constructor in C#
  • Is it possible to execute multiple SSH commands from a single login session with SSH.NET?
  • How can I get NHibernate to map to a Tuple or Class?
  • MVC 5 C# Window Authentication pop up when I navigate to a certain area
  • Mongo C# driver toJson() DateTime
  • Coprime integers
  • What is the purpose with files ending with *CS.cs in Xamarin Forms projects?
  • MVC5 / Entity | Update/Create Complex Model
  • How to return auto increment ID from SQL using Petapoco ORM in .NET MVC
  • Create new web app offline c# using Visual Studio
  • How many times is ordered the IEnumerable in this case?
  • C# error when update database 2008 to sql 2016
  • How to insert string in multiple continuous pattern in windows c#
  • How to send temp data from Partial View to its parent View
  • C# encapsulation when getting updates from asynchronous method
  • Asp net core Content Security Policy implementation
  • @Html.DropDownList() Placeholder as Disable and Selected
  • Set AM/PM in Material Time Picker WPF
  • Ninject passing reference in constructor
  • C# Entity Framework text SQL query wrapper
  • Core 2.0 MVC - AD Group Authorization for logging
  • Decentralized NLog Target per Http request
  • How to use x:Object and when?
  • Displays file icons in asp.net on GridView
  • How do I avoid two (or more) threads that work on a table at the same time to not work on same row?
  • Add xml attribute for property in DB First
  • How do i execute 2 sql queries by clicking a button [C#]
  • convert jsonstring to objects c#
  • How do request a correct access token in ASP.NET Core for Azure AD to access Microsoft Graph
  • How to run a .NET Core console application on Linux
  • UI not updating for bound element
  • C# Odata v4 open type raw values
  • DocumentFormat.OpenXml Modify Creator Propery of Document
  • How to SetBasePath in ConfigurationBuilder in Core 2.0
  • ASP MVC5 public readonly variable changes value when it should not
  • How to conditionally select item from hashset with queryable linq?
  • Progress Bar C# not showing the real progress
  • Correct logic to reconnect in SignalR with HubConnection
  • ComboBox with two or more sections
  • .NET listbox to SQLite DB
  • C# Ninject binding from Dictionary<Type, Type>
  • asp.net mvc -view displaying real-time progress status
  • Getting reference to dependent in service with generic type
  • Implementing EqualityCompare vs overriding GetHashCode and Equals
  • C# Linq Find all indexes of item in List<int> within another List<int>
  • XML image how to display at data grid columns in c#.net
  • How to override Equals and GetHash of HashSet
  • Creating Windows authentication and SQL Server authentication in login form
  • How to interop with Azure Service Bus topics created by MassTransit using Rebus?
  • MVC 5 Google Calendar Integration
  • C# - Use parallel arrays to calculate cost of a phone call in GUI
  • Use a int in entire code
  • How to display newly added element at the top of StackPanel in WPF?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org