# Все вопросы: [linq-to-objects]

107 вопросов

5ответов
657 просмотров

### Linq Arithemetic Operator combinations

When attemptiing to solve the below assignment : Using the Arithmetic operators ( +,-,*,/) rearrange four fives to equal the number 1 to 10. Example : 5/5+5-5 =1 ,5/5+5/5=2 I tried in C# without using Linq (I don't know how to proceed further) public void GetDetails() { char[]...

2ответов
719 просмотров

### Solving brain teaser using linq

At the very outset let me express my sincere thanks to Marc Gravel,Dahlbyk and the rest for helping me to apply linq practically. The following are few questions which I have faced in an interview to solve applying Linq. As I am not familiar with Linq I solved it without using Linq. I apprec...

2ответов
974 просмотров

### Handling temporary calculation in Linq

When solving an interview question Question A six digit number need to be found in such a manner when it is multiplied by an integer between 2 and 9 gives the original six digit number when its digits are reversed. Example: Suppose I multiply 219978 * 4 i get 879912 ,when reverse 879912...

1ответов
208 просмотров

### Selecting combination using linq

This is also one of the interview question i have faced recently. Description : The task is \$ 100(Please consider some currency) will be given to me.I need to purchase three items itemA,itemB,itemC.The cost of (I am not sure 0.25\$ or 0.75 \$ are meaningful,so think it as other currency) itemA=0....

3ответов
230 просмотров

### Linq Compound selection

How can i combine two arrays in to a single array during compound selection ( without using Union ) ( The question was asked at interview). var num1 = new int[] { 12, 3, 4, 5 }; var num2 = new int[] { 1, 33, 6, 10 }; I tried as var pairs = from a in num1 from b in num2 select new...

4ответов
154 просмотров

### How the transformation is possible?

int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven","eight", "nine" }; var textNums = from n in numbers select strings[n]; Console.WriteLine("Number strings:...

3ответов
1199 просмотров

### How to get the Point with minimal X from an array of Points without using OrderBy?

Imagine I have var points = new Point[] { new Point(1, 2), new Point(2, 3) }; To get the point with the minimum X I could: var result = points.OrderBy(point =&gt; point.X).First(); But for large arrays, I don't think this is the faster option. There is a faster alternative?

4ответов
1771 просмотров

### Appropriate use of keyword "new" in LINQ

Please consider the following code : string[] words = { "Too", "much", "of", "anything", "is" ,"good","for","nothing"}; var groups =from word in words orderby word ascending group word by word.Length into lengthGroups orderby lengthGroups.Key descending ...

3ответов
3401 просмотров

### Implementing Row-Level Security – (SPs vs LINQ to Objects)

I believe this is more a question about best practices and design than anything else. I tried searching for similar queries regarding this but couldn’t find any. I actually found the Row Level Security with Entity Framework but I believe the context here is a bit different. I will try to explain...

1ответов
10284 просмотров

### Select distinct values in all nested collections using LINQ to objects?

Given the following code setup: public class Foo { List&lt;string&gt; MyStrings { get; set; } } List&lt;Foo&gt; foos = GetListOfFoosFromSomewhere(); How do I get a list of all of the distinct strings in MyStrings across all of the Foo instances using LINQ? I feel like this should be easy, bu...

1ответов
1041 просмотров

### LINQ Gernic List VB.NET

I am trying to create a domain model using a product class entity an Abstract repository and a fake repository with sample data. I have created the following product class Namespace Entities Public Class Product Dim _ProductID As Integer Dim _Name As String Dim _Description As Strin...

2ответов
3981 просмотров

### How to get All select keys in Linq Group By Clause

I am trying to get the rest of the select keys in this linq query but the intellisense is giving me an error var query2 = from row2 in query1 group row2 by row2.questionid into g where g.Count() &gt; 0 select new ...

3ответов
19112 просмотров

### How to use a Distinct on a column using Linq

Here is my code: var query = from row1 in table.AsEnumerable() let time = row1.Field&lt;DateTime&gt;("time") let uri = row1.Field&lt;string&gt;("cs-uri-stem") let ip = row1.Field&lt;string&gt;("c-ip") ...

7ответов
9133 просмотров

### LINQ identity function?

Just a little niggle about LINQ syntax. I'm flattening an IEnumerable&lt;IEnumerable&lt;T&gt;&gt; with SelectMany(x =&gt; x). My problem is with the lambda expression x =&gt; x. It looks a bit ugly. Is there some static 'identity function' object that I can use instead of x =&gt; x? Something li...

1ответов
450 просмотров

### Confused about how to implement extension methods in LINQ to Objects

Fairly new to LINQ and trying to wrap my head around extension methods. What I'm attempting to do: 1) Have a table with three columns, col1 (string), col2 (double), col3 (DateTime) table1.Rows.Add("string 1", 1, new DateTime(2009, 01, 01)); table1.Rows.Add("string 1", 2, new Dat...

3ответов
162 просмотров

### Linq-to-objects processing time doubles per x iterations

I have a list of entites that contains ~137000 records that I loop through I then need to linq to a list of Tuple of additional params this contains ~ 150000 Why does it keep taking longer, the more iterations it does? Here is from the stopwatch Found: 136770 items that match the criteria. 1...

5ответов
182 просмотров

### Can a single LINQ Query Expression be framed in this scenario?

I am facing a scenario where I have to filter a single object based on many objects. For sake of example, I have a Grocery object which comprises of both Fruit and Vegetable properties. Then I have the individual Fruit and Vegetable objects. My objective is this: var groceryList = from grocer...

2ответов
3263 просмотров

### In LINQ to objects, how to set an object property to null if it equals "folder"?

I have a collection of objects representing a folder structure. I'd like to set the property FileExtension to null, if it's a folder. This is as far as I've got. Can anyone help? var items = MyClass.All().ToList(); items.ForEach(x =&gt; x.FileExtension = string.empty) .Where(y =&gt; y.Fi...

3ответов
6696 просмотров

### DataTable Select vs LINQ Select

Any advice on when DataTable.Select should be used versus LINQ Select when dealing with an in-memory DataTable? I find LINQ syntax easier and more powerful, but I'm not sure if there are performance or other issues which make a DataTable select preferable. (I'm using a third party API that prov...

2ответов
222 просмотров

### Is there a extension library specifically for LINQ to Objects?

This question comes as a logical follow-up to one of my earlier questions: Extension method for UPDATE... I would like to know if there is a library specific for LINQ to Objects ... more specifically a set of useful extensions for IEnumerable ? Here ... I do not want to know about the SQL enti...

2ответов
265 просмотров

### Need help with LINQ query that joins two tables containing periodic events

My real-life example is too obscure to explain, but this is a pretty good approximation of what I'm trying to do... Month table has columns: Id, Name Holiday table has columns: Id, MonthId, DayOfMonth, Name Appointment table has columns: Id, MonthId, DayOfMonth, Description How do I produce a...

2ответов
1360 просмотров

### How to get Lambda in LINQ to actually filter for dynamic linq

Example-I have a person class Public Class Person Private _fname As String Public Property Fname() As String Get Return _fname End Get Set(ByVal value As String) _fname = value End Set End Property Private _lname As String Public Property Lname() As String G...

3ответов
5818 просмотров

### Creating Key/Value collections using LINQ To Objects

I'm trying to use LINQ To Objects to create a query that will give me files, indexed by filename with a value mapping to their binary data as byte[]. However I can't find a 'neat' way to do this. I'm hoping to get something like a Dictionary&lt;T,K&gt; output. Here's what I have so far. Example...

4ответов
300 просмотров

### When not to use LINQ To Objects?

When should I NOT use LINQ To Objects? The inverse of this question has been asked, but didn't cover when not to use L2O.

3ответов
353 просмотров

### How linq 2 sql is translated to TSQL

It seems Linq2sql doesn't know how to construct the TSQL while you transform linq2sql object into domain object with constructors. Such as: from c in db.Companies select new Company (c.ID, c.Name, c.Location).Where(x =&gt; x.Name =="Roy"); But when using settable attributes, it will be OK. fr...

3ответов
15818 просмотров

### Generic LINQ function - SelectMany with selection Func as a parameter

I've got a class with many string arrays. I'd like to have one generic function which can get me a unique List&lt;string&gt; for a given property. Example: public class Zoo { string Name { get; set;} string[] Animals { get; set;} string[] Zookeepers { get; set;} string[] Vendors { g...

3ответов
7259 просмотров

### Extension method for UPDATE in Linq to Objects

In the following scenario, I am querying a List object and for the matching predicate I want to update some values: var updatedList = MyList .Where (c =&gt; c.listItem1 != "someValue") .Update (m =&gt; {m.someProperty = false;}); The only issue is there is n...

8ответов
29954 просмотров

### Replacing nested foreach with LINQ; modify and update a property deep within

Consider the requirement to change a data member on one or more properties of an object that is 5 or 6 levels deep. There are sub-collections that need to be iterated through to get to the property that needs inspection &amp; modification. Here we're calling a method that cleans the street add...

4ответов
31719 просмотров

### How does LINQPad reference other classes, e.g. Books in the LINQ in Action samples

I'm using LINQPad to create LINQ queries in an application I'm bulding. I noticed that in the downloaded LINQ in Action samples, e.g. example 4.04, intellisense shows a class "Books" but I don't see any references or "using" statements in the LINQPad tool, here is the sample: List&lt;Book&gt; b...

1ответов
109 просмотров

### SQL to Linq Conversion

I have sql as below SELECT Q.MaterialID AS MaterialID, Q.ProductID AS ProductID, QB.Quantity AS Quantity, Q.ParameterID AS ParameterID, SUM((Q.ParameterValue * Q.Quantity)/Q.TotalTonnes) AS ParameterValue FROM @Quality Q INNER JOIN @QuantityBreakdown QB ON ((Q.MaterialID = ...