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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/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
Linq EFCore获取两个表之间的差异_Linq_Asp.net Core_.net Core_Entity Framework Core_Ef Core 3.1 - Fatal编程技术网

Linq EFCore获取两个表之间的差异

Linq EFCore获取两个表之间的差异,linq,asp.net-core,.net-core,entity-framework-core,ef-core-3.1,Linq,Asp.net Core,.net Core,Entity Framework Core,Ef Core 3.1,我试图找出两张表之间的区别,让我们称之为昨天的员工和今天的员工。我目前正在获取所有这两个表,然后检查每个项目,以查看员工状态是否已更改或是否已删除(它们出现在昨天的表中,但不在今天的表中)。当记录数较少时,这很好,但随着记录数的增加,服务器上的网络和计算开销正在成为一个问题。有没有一种方法可以在EFCore中作为linq查询来实现这一点?(甚至两个一个用于删除,一个用于更改)请参考以下查询语句: 测试数据(您可以使用EF core从数据库中获取表值,有关在asp.net MVC中使用EF cor

我试图找出两张表之间的区别,让我们称之为昨天的员工和今天的员工。我目前正在获取所有这两个表,然后检查每个项目,以查看员工状态是否已更改或是否已删除(它们出现在昨天的表中,但不在今天的表中)。当记录数较少时,这很好,但随着记录数的增加,服务器上的网络和计算开销正在成为一个问题。有没有一种方法可以在EFCore中作为linq查询来实现这一点?(甚至两个一个用于删除,一个用于更改)

请参考以下查询语句:

测试数据(您可以使用EF core从数据库中获取表值,有关在asp.net MVC中使用EF core的更多详细信息,请检查):

输出:

输出:

要获取TodayEmployees表中的但不存在于YesterDayEmployees表中的雇员,我们可以使用来确定序列是否包含指定的元素

        //get the employees, which in TodayEmployees Table, but not exist in the YesterdayEmployee
        var query4 = (from t in todayEmployees 
                      where !(from y in yesterdayEmployees select y.EmpID).Contains(t.EmpID)
                      select t).ToList();

        var query5 = todayEmployees.Where(c => !yesterdayEmployees.Select(y => y.EmpID).Contains(c.EmpID)).Select(t => t).ToList();
输出:

        // get the employees which changes status
        var result = (from t in todayEmployees
                      join y in yesterdayEmployees
                      on t.EmpID equals y.EmpID
                      where (t.Status != y.Status)
                      select t).ToList();
        //get the employees status change information
        var query3 = (from t in todayEmployees
                      join y in yesterdayEmployees
                      on t.EmpID equals y.EmpID
                      where (t.Status != y.Status)
                      select new EmployeeViewModel()
                      {
                          EmpID = t.EmpID,
                          EmpName = t.EmpName,
                          StatusChangeLog = "change status from " + t.Status + " to " + y.Status
                      }).ToList();
        //get the employees, which in TodayEmployees Table, but not exist in the YesterdayEmployee
        var query4 = (from t in todayEmployees 
                      where !(from y in yesterdayEmployees select y.EmpID).Contains(t.EmpID)
                      select t).ToList();

        var query5 = todayEmployees.Where(c => !yesterdayEmployees.Select(y => y.EmpID).Contains(c.EmpID)).Select(t => t).ToList();