Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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# 如何检查逗号分隔值是否包含其他数组_C#_Linq - Fatal编程技术网

C# 如何检查逗号分隔值是否包含其他数组

C# 如何检查逗号分隔值是否包含其他数组,c#,linq,C#,Linq,我有以下流程列表: List<Process > process= new List<Process >() { new Process { Id=1, Name="Process 01", CostCenter="1,2,3,4,5,6,7" , companyID = 1 }, new Process { Id=2, Name="Process 02", CostCenter="1,2,3,4,10,11" , company

我有以下流程列表:

List<Process > process= new List<Process >()
    {
        new Process { Id=1, Name="Process 01", CostCenter="1,2,3,4,5,6,7" , companyID = 1  },
        new Process { Id=2, Name="Process 02", CostCenter="1,2,3,4,10,11" , companyID = 1  },
        new Process { Id=2, Name="Process 03", CostCenter="1,2,5"         , companyID = 1  },
    }

    List<orderDetails> process= new List<orderDetails>()
    {
        new orderDetails{ Id=1, Name="order 01", CostCenterId="1" , companyID = 1  },
        new orderDetails { Id=2, Name="order 02", CostCenterId="2" , companyID = 1  },
    }

有什么想法吗?

你的问题不是很清楚,在评论中应该会有一些混乱。据我所知,您正在寻找包含所有订单详细信息的CostCenterId的流程。如果是:

var processes = process
    .Where(p => 
         orderDetails.All(d => $",{p.CostCenter},"
             .Contains($",{d.CostCenterId},")));

首先,提供的代码不会编译。请提供您试图编写的函数的预期输出,并给出一些示例。将此信息添加到您的问题中。如果您无法用纸和笔解决简单的用例,请不要开始编写代码。我的问题我需要从订单明细表中获取一个包含成本中心的流程。?我的问题我需要从订单明细表中获取一个包含成本中心的流程。?我尝试了上面的示例,但没有解决,并返回此错误:LINQ to Entities无法识别方法的System.String格式(System.String,System.Object)'方法,而此方法无法转换为存储表达式。@WaleedAl akrabawe,您的代码与LinqToEntities无关,您应该指定它。如果在值中添加前缀、后缀逗号,则可以不使用字符串插值。
var processes = process
    .Where(p => 
         orderDetails.All(d => $",{p.CostCenter},"
             .Contains($",{d.CostCenterId},")));