Lig*_*ark 3 c# linq asp.net-mvc entity-framework
我正在尝试将连接返回到我的班级,它给了我以下错误.
错误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();
}
Run Code Online (Sandbox Code Playgroud)
关注我的实体
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; }
}
Run Code Online (Sandbox Code Playgroud)
您不需要Join为每一行返回产品,您只需要包含产品然后返回它们,如:
return context.Lines.Include("Products").ToList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
110 次 |
| 最近记录: |