1
我的应用程序是.net核心MVC。我有两个类asp.net c#linq从模型库生成列表从另一个列表中的编号
public class Product
{
public int Id { get; set; }
public string Buyer { get; set; }
public int? ProductId { get; set; }
public ProductType ProductType { get; set; }
}
public class ProductType
{
public int ProductId { get; set; }
public string ProductName { get; set; }
public ICollection<Product> Product { get; set; }
}
我想用下面生成的产品名称的列表:
List<ProductType> productnames;
var products = _context.Product().Where(x => x.Buyer == "Test" && x.ProductId != null).ToList();
foreach (var item in products)
{
productnames = _context.ProductType.Where(c => c.ProductId == item.ProductId).ToList();
}
虽然我已经在列表(产品)3项,我得到的只是一个项目产品名称列表。
注意:我无法使用Include,因为我使用另一个Core Web API检索数据,并且 无法使用oData返回IQueryable对象。所以作为一种解决方法,我是 使用Sqlite作为客户端应用程序,而API使用MS Sql。
@StephenMuecke简化这个,谢谢。它效果很好。 – hncl
所以用绿色的勾子检查他的答案 – GGO