Flezcano
Flezcano

Reputation: 1687

'Get' logic when using automapper

This is my Entity:

public class CouponEntity
{
    public int CouponId { get; set; }
    public int CompanyNumber { get; set; }
    public string Name { get; set; }
    public string FileName { get; set; }

    public string CompanySlug
    {
        get
        {
            return COMMONCONSTANTS.URL_COMPANY + "/" + this.CompanyNumber;
        }
    }
}

And the following is my DTO:

public class CouponDto
{    
    [DataMember]
    public string CompanySlug { get; set; }
    [DataMember]
    public string FileName { get; set; }
    [DataMember]
    public string Name { get; set; }
}

My question is: does using Mapper.Map<IEnumerable<CouponEntity>, IEnumerable<CouponDto>>(lstProducts) greatly affect performance?

I got the following from the AutoMapper creator somewhere on the Internet:

DTO is a strict projection of the data model. No business logic in mapping 99% "Auto" - restrict customization to minimum Prefer LINQ projection

So, is this what should be avoided? Is there a better way to accomplish this?

Upvotes: 0

Views: 82

Answers (1)

Merkle Groot
Merkle Groot

Reputation: 906

In this scenario, using AutoMapper is unlikely to have a noticeable impact on performance. Creating the map, Mapper.CreateMap(), does tend to have an impact on performance, so be sure that you only call CreateMap() once when the application starts.

Upvotes: 1

Related Questions