0

I have this table using Entity Framework code first approach :

 public class WebsitePart
{
    public WebsitePart()
    {
        SubParts = new HashSet<WebsitePart>();
    }

    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    public Nullable<int> ParentId { get; set; }

    [StringLength(100)]
    [Index("UQ_WebsitePart_Key", IsUnique = true)]
    public string Key { get; set; }

    public virtual WebsitePart Parent { get; set; }

    public virtual ICollection<WebsitePart> SubParts { get; set; }
}

I need after getting the list of WebsiteParts to map it into List of another model where each element of this list has ParentId=null and down to the end of its grandsons(traversing) .

This the model I want to map to:

   public class WebPartViewDto
{
    public int Id { get; set; }

    public string Key { get; set; }

    public IList<WebPartViewDto> SubWebParts { get; set; }
}

Could you please show me how to map it with performance is taken into account?

Simple Code
  • 2,354
  • 2
  • 27
  • 56
  • You could use [Automapper](http://automapper.org/) – Izzy Oct 30 '17 at 08:51
  • Possible duplicate of [DTO to Entity Mapping Tool](https://stackoverflow.com/questions/9770041/dto-to-entity-mapping-tool) – Izzy Oct 30 '17 at 08:52

0 Answers0