Return Join Linq C #

3

I'm trying to return a join for my class and it's giving me the following error

  

Error 1 Can not implicitly convert type   'System.Collections.Generic.List' in   'System.Collections.Generic.List' C: \ Projects \ ASP.NET \ AdvanceTechniques \ Models \ Repository \ ProductRepository.cs 40 30 AdvanceTechniques

Follow the code below.

public List<Line> Get()
{
    return context.
        Lines.
        Join(
            context.Products,
            lines => lines.ID,
            products => products.LineID,
            ((products, lines)
                => new { lines, products}
        )).
        OrderByDescending(products => products.products.ID).ToList();
}

Follow my Entity

public partial class Line
    {
        public Line()
        {
            this.Products = new List<Product>();
        }
        [Required]
        public long ID { get; set; }
        [Required]
        public string Name { get; set; }
        [Required]
        public string Slug { get; set; }
        [Required]
        public string DesktopImage { get; set; }
        [Required]
        public string MobileImage { get; set; }
        [Required]
        public string AltImage { get; set; }
        [Required]
        public int Position { get; set; }
        [Required]
        public bool IsActive { get; set; }

        public virtual List<Product> Products { get; set; }
    }
    
asked by anonymous 19.08.2014 / 15:36

1 answer

3

An error occurs because you are not returning a list of Line . Try this:

public List<Line> Get()
{
    return context.
        Lines.
        Join(
            context.Products,
            lines => lines.ID,
            products => products.LineID,
            ((products, lines)
                => new { lines, products}
        ))
        .Select(s => s.lines)
        .OrderByDescending(p => p.products.ID).ToList();
}

But, it does not make sense to use Join . If you are not going to use Where to filter the data, you are simply gathering values from 2 tables. Being Line already has a list of products .. I hope I have helped

    
19.08.2014 / 16:44