Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public class ModuleDTO
    {
        public int ModuleID { get; set; }
        public int ProjectID { get; set; }
        public string ModuleName { get; set; }
        public string ModuleVer { get; set; }
        public bool Active { get; set; }       
        public virtual ProjectDTO ProjectDTO { get; set; }
    }

public class ProjectDTO
    {
       public ProjectDTO()
        {
            this.ModuleDTO = new HashSet<ModuleDTO>();
        }

        public int ProjectID { get; set; }
        public string ProjectName { get; set; }
        public string ProjectVer { get; set; }
        public bool Active { get; set; }
        public virtual ICollection<ModuleDTO> ModuleDTO { get; set; }

    }

// How can i use Auto Mapper instead of below code in C#?
      I am confused to make a relationship syntax in Automapper it gives Error.


using (TicketSystemEntities DB = new TicketSystemEntities())
            {
                var Module = from m in DB.SP_GetModules(0)
                             select new ModuleDTO
                             {
                                 ModuleID = m.ModuleID,
                                 ModuleName = m.ModuleName,
                                 ModuleVer = m.ModuleVer,
                                 ProjectID = m.ProjectID,
                                 ProjectDTO = new ProjectDTO
                                 {
                                     ProjectName = m.ProjectName
                                 }
                             };
                return Module.SingleOrDefault();
            }


The Below Simple Automapper Works Fine but i want Project name using ForeinKey Relationship between ModulesDTO and ProjectDTO Class. plz Help me..

C#
Mapper.CreateMap<SP_GetModules_Result, ModuleDTO>();         
 return Mapper.Map<IEnumerable<ModuleDTO>>(DB.SP_GetModules(0).AsEnumerable());  


What I have tried:

I have to take ProjectName from DB.SP_GetModules(0) Result Set And Add it to ProjectDTO Which is the Virtual class properties of ModuleDTO to Show Which Projectname of Module in Result Set.

Using Automapper......
Posted
Updated 14-Feb-16 20:18pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900