Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取包含where子句的集合作为Linq中的集合_C#_Linq_Where Clause - Fatal编程技术网

C# 获取包含where子句的集合作为Linq中的集合

C# 获取包含where子句的集合作为Linq中的集合,c#,linq,where-clause,C#,Linq,Where Clause,以下是我的服务方法: public List<RelatedInvoiceData> GetRelatedInvoices(InvoiceSearch invoiceSearchFilters) { List<InvoiceInfoView> invoices = _wiseStepDbContext.InvoiceInfoView.Where(i => i.RecruiterCompanyId == _securityManager.CurrentRec

以下是我的服务方法:

 public List<RelatedInvoiceData> GetRelatedInvoices(InvoiceSearch invoiceSearchFilters)
 {
   List<InvoiceInfoView> invoices = _wiseStepDbContext.InvoiceInfoView.Where(i => i.RecruiterCompanyId == _securityManager.CurrentRecruiterCompanyId).ToList();

   List<RelatedInvoiceData> relatedInvoiceViewCollection = GetRelatedInvoiceCollection(invoices);

   if (invoiceSearchFilters.CustomerId > 0)
   {
        relatedInvoiceViewCollection = relatedInvoiceViewCollection.Where(i => i.CustomerId == invoiceSearchFilters.CustomerId).ToList();
   }

   if (invoiceSearchFilters.VendorId > 0)
   {
        relatedInvoiceViewCollection = relatedInvoiceViewCollection.Where(i => i.VendorId == invoiceSearchFilters.VendorId).ToList();
   }

   return relatedInvoiceViewCollection;
}
以前我在linq中使用where来表示单个客户Id,现在我希望过滤器具有多个CustomerID和多个VendorID


现在我想使用customerid数组。如何在Where子句中为数组编写LINQ。感谢您的帮助

如果我理解正确,您的意思是
I.CustomerId
现在是一个数组或
列表
。如果是这种情况,则可以使用
.Contains()
方法。类似这样的操作应该满足您的需要:
relatedInvoiceViewCollection=relatedInvoiceViewCollection.Where(i=>i.CustomerId.Contains(invoiceSearchFilters.CustomerId)).ToList()

编辑:如果您想在两个数组中检查,这可能会有所帮助,您可以这样做:
relatedInvoiceViewCollection=relatedInvoiceViewCollection.Where(i=>i.CustomerId.Intersect(invoiceSearchFilters.CustomerId.Any()).ToList()


排序取决于您使用的LINQ变体(例如,LINQ到对象、LINQ到实体等)。不同的变体支持不同的操作符和操作子集。我提出的问题可能是错误的,我已经更新了问题,并有明确的要求。检查问题,更新我在提出正确问题时的错误。更新问题请检查要求并更新ans。
public class InvoiceSearch
    {
        public int[] CustomerId { get; set; }

        public int[] VendorId { get; set; }
    }
relatedInvoiceViewCollection.Where(x => relatedInvoiceViewCollection.Contains(invoiceSearchFilters.CustomerId)).ToList(); 
relatedInvoiceViewCollection.Where(x => x.Contains(invoiceSearchFilters.CustomerId)).ToList();