且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

IQueryable.Distinct()VS名单< T> .Distinct()

更新时间:2022-01-10 15:56:38

显然,你不能有确切的重复行(包括主键)在表格中。也许你的意思是用一些相同的字段(不包括主键)行。

Obviously you cannot have exact duplicate rows (including the primary key) in your table. Probably what you mean is rows with some equal fields (excluding primary key).

调用鲜明的IQueryable ,产生的查询结果,你的表的每一个领域比较针对对方一个SQL DISTINCT 运营商。因为你不能在表中准确重复行,它返回的所有行。

Calling Distinct on IQueryable, generates a SQL DISTINCT operator on the resulting query, which compares every field of your table against each other. Because you cannot have exact duplicate rows in the table, it returns all the rows.

在另一方面,要求鲜明列表<使用者&GT; 将使用等于用户的方法对象在内存比较对象(从数据库中获取所有行之后)。最终的结果取决于等于的方法,它可以检查只对相等的值某些字段。

On the other hand, calling Distinct on a List<User> will use Equals method of the User object to compare objects in memory (after fetching all the rows from database). The final result depends on the implementation of Equals method, which could check only some fields for equal values.