我正在使用實體框架6與C#。實體框架搜索實體屬性和實體ICollection
我的表就像;
public class Product
{
public Product()
{
ProductInfos = new List<ProductInfo>();
}
...
public string Name { get; set; }
public virtual ICollection<ProductInfo> ProductInfos { get; set; }
}
public class ProductInfo
{
...
public long ProductId { get; set; }
public string Name { get; set; }
}
我想在Product.Name
和Product.ProductInfos
搜索文本 - >Name
。
喜歡;
queryable = queryable.Where(x => x.Name.Contains(searchtext))
.Where(p => p.ProductInfos.Where(p => p.Name.Contains(searchtext)));
但是,你可以看到我的大腦已經停止:)
如何查詢類的屬性和子類的屬性?
P.s.這不是大表,不用擔心表現錯誤。我只有50種產品。
什麼是錯誤?結果是什麼?你測試了你的查詢嗎? – CodeNotFound