实体框架搜索实体属性和实体ICollection

问题描述:

我正在使用实体框架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.NameProduct.ProductInfos搜索文本 - >Name
喜欢;


        queryable = queryable.Where(x => x.Name.Contains(searchtext)) 
             .Where(p => p.ProductInfos.Where(p => p.Name.Contains(searchtext))); 

但是,你可以看到我的大脑已经停止:)
如何查询类的属性和子类的属性?

P.s.这不是大表,不用担心表现错误。我只有50种产品。

+0

什么是错误?结果是什么?你测试了你的查询吗? – CodeNotFound

queryable = queryable.Where(x => x.Name.Contains(searchtext) || 
           x.ProductInfos.Any(y => y.Name.Contains(Seachtext)); 
+0

虽然此代码片段可能会解决问题,但[包括解释](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)确实有助于提高帖子的质量。请记住,您将来会为读者回答问题,而这些人可能不知道您的代码建议的原因。 –