How to implement pivot data in Entity Framework?

Viewed 2944

I have created following models in ASP.NET MVC. Now I have to send products data by API or JSON format.

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }

    public virtual IList<ProductAttribute> ProductAttributes { get; set; }
}

public class ProductAttribute
{
    public int Id { get; set; }
    public int ProductId { get; set; } //foreign key
    public string Key { get; set; }
    public string Value { get; set; }
}

Currently data comes in this way after converting into JSON. enter image description here

But I want to convert it into Pivot view, something like this.

enter image description here

How can I do this by using Entity Framework or LINQ ? Thanks

1 Answers
Related