R – Data Transfer Objects and Entity Framework

entityentity-framework

I am working on a 3-tier web application where I am using the microsoft Entity Framework.
To make a loose coupling between the different layers I using data transfer objects to transfer between the Entity Framework objects and my custom objects, but I have a problem with the speed of translating between the entity framework and my custom DTO's.
I use this method to transfer from EF to DTO:


public List Transform(List carModelDefinition)
{

        List<CarDefinitionDTO> cdDTOList = new List<CarDefinitionDTO>();
        foreach (DataLayer.CarModelDefinition cmd in carModelDefinition)
        {
            CarDefinitionDTO cdDTO = new CarDefinitionDTO();
            cdDTO.CarDefinitionId = cmd.CarModelDefinitionId;
            cdDTO.Compagny = cmd.Company;
            cdDTO.Model = cmd.Model;
            cdDTOList.Add(cdDTO);
        }
        return cdDTOList;

}

But when I try to transfer a list of e.g. 600 elements i takes about 10+ seconds. Am I doing something wrong, or is the speed simply this slow?
NB. I am working on a pretty fast PC so it is not the speed of my pc which slows it down.

Best Answer

I found the error. In the constructor I create the instance of the Entity manager, and when I created a new object it would create a new instance all the time, which was quite time consuming.