Does "Count ()" after "Take ()" on "IQueryable" return an incorrect result?

After executing the take(n)linq method on the IQueriable data (initial counter m), the method Count()still returns a value m.

Does the command ToList()execute the only option to get the actual score from IQueryable?

var data = service.Get();//100 records
var data2 = data.Take(10);

var count = data2.count(); //result 100 - wrong
var count2 = data2.ToList().Count; // result 10 - correct
+4
source share
1 answer

You should use ToList () for this case or find an alternative solution or limit the result of Count () yourself (since the correct value can never be greater than the value specified for Take ()).

NHibernate: https://nhibernate.jira.com/browse/NH-2477

+4

Source: https://habr.com/ru/post/1649174/


All Articles