C# 使用LINQ,获取包含特定属性值的对象列表

C# 使用LINQ,获取包含特定属性值的对象列表,c#,.net,asp.net-mvc,linq,C#,.net,Asp.net Mvc,Linq,我有两个简单的模型: public class Product() { public long CategoryId {get; set;} //...etc } public class ProductCategory() { public long Id {get; set;} //...etc } 我编写了一个查询来存储Produc

我有两个简单的模型:

 public class Product()
        {
           public long CategoryId {get; set;}
           //...etc
        }

 public class ProductCategory()
        {
           public long Id {get; set;}
           //...etc
        }
我编写了一个查询来存储ProductCategory.Id号列表

List<long> activeProductCategories
列出activeProductCategories
现在,我想编写一个Linq查询,获取CategoryId等于activeProductCategories中任意long的所有产品的列表

我已经开始写以下内容,但尚未取得很大进展:

List<Product> activeProducts = UnitOfWork.ProductRepository.Get().Where(a=>a.CategoryId //... ?
List activeProducts=UnitOfWork.ProductRepository.Get()。其中(a=>a.CategoryId/?

您可以使用linq
Contains()
方法

List<Product> activeProducts = UnitOfWork.ProductRepository.Get()
    .Where(a => activeProductCategories.Contains(a.CategoryId)).ToList();
List activeProducts=UnitOfWork.ProductRepository.Get()
.Where(a=>activeProductCategories.Contains(a.CategoryId)).ToList();
.Where(a=>activeProductCategories.Contains(a.CategoryId);