Return Join Linq C #
I am trying to return a connection to my class and it gives me the following error.
Error 1 Could not implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List' C: \ Projetos_ASP.NET \ AdvanceTechniques \ Models \ Repository \ ProductRepository.cs 40 30 AdvanceTechniques
Executes the following code.
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 essence
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; }
}
+3
LigDark
source
to share
1 answer
You don't need to Join
return products for every row, you only need to include products and then return them like this:
return context.Lines.Include("Products").ToList();
+6
Habib
source
to share