linq

LINQ performance - deferred v/s immediate execution

♀尐吖头ヾ 提交于 2021-02-07 08:56:03
问题 I have seen that sometimes the performance of LINQ to Objects queries can be improved significantly if they forced to execute immediately by using .ToArray() , but can't quite understand why. For example, in the sample below, the execution of the function Deferred() is much slower than the function Immediate() , and grows exponentially with the value of limit (perhaps it was exponential in both functions, but execution time with Immediate() was too little for me to say definitively). public

LINQ performance - deferred v/s immediate execution

只谈情不闲聊 提交于 2021-02-07 08:55:42
问题 I have seen that sometimes the performance of LINQ to Objects queries can be improved significantly if they forced to execute immediately by using .ToArray() , but can't quite understand why. For example, in the sample below, the execution of the function Deferred() is much slower than the function Immediate() , and grows exponentially with the value of limit (perhaps it was exponential in both functions, but execution time with Immediate() was too little for me to say definitively). public

LINQ performance - deferred v/s immediate execution

谁说我不能喝 提交于 2021-02-07 08:53:55
问题 I have seen that sometimes the performance of LINQ to Objects queries can be improved significantly if they forced to execute immediately by using .ToArray() , but can't quite understand why. For example, in the sample below, the execution of the function Deferred() is much slower than the function Immediate() , and grows exponentially with the value of limit (perhaps it was exponential in both functions, but execution time with Immediate() was too little for me to say definitively). public

C#: Iterating through a data table: Rows, Select() or AsEnumerable()

可紊 提交于 2021-02-07 07:12:37
问题 foreach (DataRow row in myDataTable.Select()) foreach (DataRow row in myDataTable.AsEnumerable()) foreach (DataRow row in myDataTable.Rows) Any differences? 回答1: Rows isn't strongly typed - so there will be a cast on each iteration, and you can't use LINQ to objects on it easily. (I believe AsEnumerable() will have to cast on each iteration internally as well, but at least you can use it for other LINQ methods easily.) Select needs to build an array, so there's obviously a performance penalty

C#: Iterating through a data table: Rows, Select() or AsEnumerable()

独自空忆成欢 提交于 2021-02-07 07:12:21
问题 foreach (DataRow row in myDataTable.Select()) foreach (DataRow row in myDataTable.AsEnumerable()) foreach (DataRow row in myDataTable.Rows) Any differences? 回答1: Rows isn't strongly typed - so there will be a cast on each iteration, and you can't use LINQ to objects on it easily. (I believe AsEnumerable() will have to cast on each iteration internally as well, but at least you can use it for other LINQ methods easily.) Select needs to build an array, so there's obviously a performance penalty

C#: Iterating through a data table: Rows, Select() or AsEnumerable()

那年仲夏 提交于 2021-02-07 07:10:59
问题 foreach (DataRow row in myDataTable.Select()) foreach (DataRow row in myDataTable.AsEnumerable()) foreach (DataRow row in myDataTable.Rows) Any differences? 回答1: Rows isn't strongly typed - so there will be a cast on each iteration, and you can't use LINQ to objects on it easily. (I believe AsEnumerable() will have to cast on each iteration internally as well, but at least you can use it for other LINQ methods easily.) Select needs to build an array, so there's obviously a performance penalty

Chaining OR conditions in EF 5.0

人走茶凉 提交于 2021-02-07 06:23:41
问题 I will preface this with I'm actively searching for the solution to this problem but figured I might short cut some research and development time if someone here on stack has already figured this out. (I have found nothing online so here goes) We have a case in an application framework we are building where we need the capability to take in a set of Predicates ( List<Expression<Func<T,bool>>> ) and parse it in a search framework. Right now we have the capability to filter in this way being

Chaining OR conditions in EF 5.0

浪尽此生 提交于 2021-02-07 06:23:36
问题 I will preface this with I'm actively searching for the solution to this problem but figured I might short cut some research and development time if someone here on stack has already figured this out. (I have found nothing online so here goes) We have a case in an application framework we are building where we need the capability to take in a set of Predicates ( List<Expression<Func<T,bool>>> ) and parse it in a search framework. Right now we have the capability to filter in this way being

Invalid anonymous type member declarator in LINQ

折月煮酒 提交于 2021-02-07 05:21:24
问题 I have two entities. One is "Students" while another is "Subjects". The details of the two entities is something like: students { id, name} subjects { studentID, subjectName, passed} where "passed" is of boolean type. Now I want to query the student name and count of subject that he can pass with follows: var result = from s in db.students select new {s.name, s.subjects.Count(i => i.passed.Equals(true)}; But i get error msg:Invalid anonymous type member declarator. Anonymous type members must

About System.Linq.Lookup class

落爺英雄遲暮 提交于 2021-02-07 05:04:12
问题 I came across this class while reading a C# book and have some questions. Why is this added into System.Linq namespace and not into usuall Collections namespace? What the intention behind this class is Why this class is not intended for direct instantiation? This is available through the ToLookup extension only, right? 回答1: Purpose of the class: a dictionary where a key can map to multiple values. Think of it as being for grouping rather than one-to-one mapping. Only through ToLookup decision