Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.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# Linq和实体框架在非主键值上不同_C#_Mysql_Entity Framework_Linq - Fatal编程技术网

C# Linq和实体框架在非主键值上不同

C# Linq和实体框架在非主键值上不同,c#,mysql,entity-framework,linq,C#,Mysql,Entity Framework,Linq,我有表1,其中只包含零件号 我有表2,其中包含零件号以及许多其他与之相关的字段,我都需要得到这些字段 我需要从表2中获得表1中没有零件号的所有零件 我还需要从表2中得到不同的零件号。零件号不是表2中的主键。表2有超过300万条记录,所以多条语句可能并不明智 context.Parts.Where(x => !partmasterids.Contains(x.PartNumber)).ToList(); 这应该达到所有标准,除了获得不同的回报 context.Parts.GroupBy(x

我有表1,其中只包含零件号

我有表2,其中包含零件号以及许多其他与之相关的字段,我都需要得到这些字段

我需要从表2中获得表1中没有零件号的所有零件

我还需要从表2中得到不同的零件号。零件号不是表2中的主键。表2有超过300万条记录,所以多条语句可能并不明智

context.Parts.Where(x => !partmasterids.Contains(x.PartNumber)).ToList();
这应该达到所有标准,除了获得不同的回报

context.Parts.GroupBy(x=>x.PartNumber)。选择(x=>x.First())。其中(x=>
!partmasterids.Contains(x.PartNumber)).ToList()

我尝试了上面的LINQ语句,并在groupby中移动到where语句之后,但它不起作用


如果First()出现错误,FirstOrDefault将无休止地运行。Distinct甚至不起作用。我不知道如何编写正确的LINQ语句。

我假设您已经在
partmasterids
中有了TableA

以及上述声明中缺失的部分(表B表A):
var missingParts=context.Parts.Where(x=>!partmasterids.Contains(x.PartNumber)).ToList()

那么,不同的零件号是否就是tableaunion(TableB TableA)


你能提供表1和表2的实体类吗?另一个选择,没有太大的不同,但。。。context.Parts.Where(x=>!parmasterids.Any(y=>y==x.PartNumber)).DistinctBy(x=>x.PartNumber).ToList()
var allPartNumbers = partmasterid.Union(missingParts.Select(p=>p.PartNumber)).Distinct();