linq

About System.Linq.Lookup class

拈花ヽ惹草 提交于 2021-02-07 05:03:34
问题 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

C# Linq: Combine multiple .Where() with an *OR* clause

北战南征 提交于 2021-02-07 04:54:10
问题 I have been searching a lot about my current problem but I could not find a real answer to solve that issue. I am trying to build a LINQ Query that produces the following SQL: SELECT * FROM TABLE WHERE (Field1 = X, Field2 = Y ... ) or (Field3 = Z) In a normal situation I would just do this: Object.Where(c => (c.Field1 == X && c.Field2 == Y) || (c.Field3 == Z)) I cannot use this approach because the query is build by using multiple .Where() calls. Having an example: // This is a short example,

How to avoid OrderBy - memory usage problems

百般思念 提交于 2021-02-07 04:54:05
问题 Let's assume we have a large list of points List<Point> pointList (already stored in memory) where each Point contains X, Y, and Z coordinate. Now, I would like to select for example N% of points with biggest Z-values of all points stored in pointList . Right now I'm doing it like that: N = 0.05; // selecting only 5% of points double cutoffValue = pointList .OrderBy(p=> p.Z) // First bottleneck - creates sorted copy of all data .ElementAt((int) pointList.Count * (1 - N)).Z; List<Point>

Using lambda function in a foreach over controls [duplicate]

*爱你&永不变心* 提交于 2021-02-07 04:37:14
问题 This question already has answers here : Foreach Control in form, how can I do something to all the TextBoxes in my Form? (14 answers) Closed 3 years ago . I would like to translate this: foreach(Control c in Controls) { if(c is TextBox) { // ... } } Into: foreach(Control c => (c is TextBox) in Controls) { // ... } How can it be done using the lambda function specifically? 回答1: Reference Linq: using System.Linq; And use this: foreach (var control in Controls.Cast<Control>().Where(c => c is

Autocomplete textbox freezes while executing query. Must be a better way!

倾然丶 夕夏残阳落幕 提交于 2021-02-07 03:42:22
问题 everyone! I searched the best I could and did not find exactly the help I was looking for. Problem AutoCompleteTextbox FREEZES and "eats" characters while query is performed Asking for Mimic Google Instant functionality Background First things first: C#, WPF, .NET 4.0 Ok, now that's out of the way, I'm trying to find the best way to implement a dynamic AutoComplete Textbox, which queries a database for results after each letter typed. The following code gets executed when the

Autocomplete textbox freezes while executing query. Must be a better way!

て烟熏妆下的殇ゞ 提交于 2021-02-07 03:40:14
问题 everyone! I searched the best I could and did not find exactly the help I was looking for. Problem AutoCompleteTextbox FREEZES and "eats" characters while query is performed Asking for Mimic Google Instant functionality Background First things first: C#, WPF, .NET 4.0 Ok, now that's out of the way, I'm trying to find the best way to implement a dynamic AutoComplete Textbox, which queries a database for results after each letter typed. The following code gets executed when the

Autocomplete textbox freezes while executing query. Must be a better way!

流过昼夜 提交于 2021-02-07 03:39:55
问题 everyone! I searched the best I could and did not find exactly the help I was looking for. Problem AutoCompleteTextbox FREEZES and "eats" characters while query is performed Asking for Mimic Google Instant functionality Background First things first: C#, WPF, .NET 4.0 Ok, now that's out of the way, I'm trying to find the best way to implement a dynamic AutoComplete Textbox, which queries a database for results after each letter typed. The following code gets executed when the

Implementing a custom QueryProvider with in-memory query

别等时光非礼了梦想. 提交于 2021-02-07 02:00:41
问题 I'm trying to create a wrapper around QueryableBase and INhQueryProvider that would receive a collection in the constructor and query it in-memory instead of going to a database. This is so I can mock the behavior of NHibernate's ToFuture() and properly unit test my classes. The problem is that I'm facing a stack overflow due to infinite recursion and I'm struggling to find the reason. Here's my implementation: public class NHibernateQueryableProxy<T> : QueryableBase<T>, IOrderedQueryable<T>

IEqualityComparer for Annoymous Type

隐身守侯 提交于 2021-02-06 12:27:22
问题 Firstly I have seen IEqualityComparer for anonymous type and the answers there do not answer my question, for the obvious reason that I need an IEqualityComparer not and IComparer for use with Linq's Distinct() method. I have checked the other answers too and these fall short of a solution... The Problem I have some code to manipulate and pull records in from a DataTable var glext = m_dtGLExt.AsEnumerable(); var cflist = (from c in glext orderby c.Field<string>(m_strpcCCType), c.Field<string>

IEqualityComparer for Annoymous Type

那年仲夏 提交于 2021-02-06 12:27:14
问题 Firstly I have seen IEqualityComparer for anonymous type and the answers there do not answer my question, for the obvious reason that I need an IEqualityComparer not and IComparer for use with Linq's Distinct() method. I have checked the other answers too and these fall short of a solution... The Problem I have some code to manipulate and pull records in from a DataTable var glext = m_dtGLExt.AsEnumerable(); var cflist = (from c in glext orderby c.Field<string>(m_strpcCCType), c.Field<string>