[英]Return Join Linq C#
我正在嘗試將連接返回到我的班級,它給了我以下錯誤。
錯誤1無法將類型'System.Collections.Generic.List'隱式轉換為'System.Collections.Generic.List'C:\\ Projetos_ASP.NET \\ AdvanceTechniques \\ Models \\ Repository \\ ProductRepository.cs 40 30 AdvanceTechniques
請遵循以下代碼。
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();
}
關注我的實體
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; }
}
您不需要Join
來為每一行返回產品,您只需要包含產品然后返回它們,如:
return context.Lines.Include("Products").ToList();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.