Language Integrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages.

learn more… | top users | synonyms

4
votes
1answer
49 views

More effecient way of running this LINQ

So, what the function is supposed to do is count the number of times each letter appears in a string, then display the one that appears the most, and the number of times it appears. If there's a tie, ...
1
vote
1answer
39 views

Optimize Implementation - Wait for all threads using LINQ

In my program I read several information's about the system. I read each categories like CPU, memory, services, software and so on with a own thread. The main program have to wait for the longest ...
3
votes
3answers
181 views

Linq query performance improvements

As I am getting my Linq query to a functional point, I start looking at the query and think about all the "ANY" , and wonder if those should be a different method and then I have data conversions ...
5
votes
2answers
112 views

Improvement requested for: Generic Calculator and Generic Number

.NET does not support generic numbers. It is not possible to enforce a generic method with generic argument T that T is a number. The following code will simply not compile: public T ...
2
votes
3answers
124 views

Using Linq to select the first and last values

I want to get just the first and last values in a date range. I have the following code: using (var myEntities = new dataEntities()) { var myValues = (from values in myEntities.PointValues ...
2
votes
1answer
38 views

XML to Windows.Forms.Keys List

It took me a lot of poking around and unit testing to get the code to look like it is right now. So I have a XML file which in part looks like this <FunctionKeys> ...
4
votes
3answers
160 views

LINQ Group query - simplifying

Is there a way of writing this correctly working query more efficiently? I'm asking only to learn LINQ better: var cpuInfo = edgeLPs .GroupBy(k => k.CPU.ID, e => e.CPU) ...
2
votes
1answer
122 views

Is there a more elegant way to rewrite this piece of code?

This is what happens, i have a dropdownbox "ActiviteitAardItems" where ActiviteitAard items can be checked (checkbox). If one (or more) are checked the property Opacity will be changed, and the code ...
3
votes
1answer
82 views

LINQ statement to aggregate data

Teachers can raise 'dramas' which are when students forget equipment, don't do homework or are flagged for concern. Each drama for each student is stored as a separate record. I seek a list of all ...
1
vote
1answer
124 views

MVC4 Linq to Sql Model Structure

Goal: To pass a list of related objects into a view which can then be iterated over using razor syntax. I'm new to LINQ and MVC4. I'm trying to use the repository pattern to manage my model creation. ...
6
votes
2answers
132 views

Left hand search in string

the requirement for our search query is to look for all search words in the beginning of vehicle manufacturer, model and variant name. Case insensitive. The word being a string of characters separated ...
0
votes
1answer
81 views

making this linq query faster

I need the most efficient way to get the value of the searchName, or if null return searchName. I am returning just a single string, so maybe I should search itemRepository.Item instead of Items ...
3
votes
2answers
99 views

Refactoring from .. in .. select to more compact one

Is it possible to write the two following lines of code in a more compact one? IEnumerable<int> collection = from partnerNumbers in contract.Contact.PartnerNumbers select partnerNumbers.Pnr; ...
3
votes
3answers
248 views

Rewrite from .. where .. select to more compact one

This is the code: public DateTime GibSomeStartDate(IEnumerable<int> partnerNumbers, DateTime startTime) { return (from contract in this.databaseContext.Contract where ...
3
votes
4answers
117 views

Finding unconnected sets

I have a list of boxes, and wish to group them into unconnected sets of overlapping boxes. (Note that two boxes A and B may not overlap each other, but if they are both overlapped by a box C, they ...
0
votes
3answers
114 views

New to LINQ, not sure this is best practice

So i have a super class that has a 3 child classes. Those 3 child classes have multiple classes of their own. I was having troubles saving this into XML, so I decided to parse it out and do a little ...
1
vote
1answer
35 views

Linq to sql performance

I'm creating a system and I'm using EF with Linq. Model First. So I create my Model (.edmx) and using it, I generated my database and my classes. like the Usuario (user in portugues. going to keep ...
2
votes
2answers
178 views

To LINQ or not to LINQ

As a fairly new C# programmer I am a unsure about when and how to best make use of LINQ (and also when to choose the expression method syntax vs. the query syntax). This question often comes up for me ...
2
votes
2answers
77 views

Optimizing a distinction code

List<int> types = new List<int>(); foreach (var d in myTableList) { if (!types.Contains((int)d.item_type)) types.Add((int)d.item_type); } I have a table in db called myTable. ...
1
vote
1answer
53 views

(More) efficient and elegant way to retrieve data from a dataset?

I have a DataSet with only two tables in it. The first table is a list of models (of products) with default parameters (settings), and the second table is a list of modules. A module is a product ...
0
votes
2answers
96 views

Better way to write this fold operation?

I often have code that looks like this: boolean isFirst = true; var builder = new StringBuilder(); foreach (var foo in source) { //source might be empty if (isFirst) { isFirst = false; } ...
4
votes
2answers
261 views

Improving performance of a LINQ to Entities query with lots of grouping

I have been presented with a simple but slow performing LINQ to Entities query which I've pasted below. Could anybody give me some pointers on how to improve performance? The query below has been ...
8
votes
2answers
212 views

String join of distinct string

I have a class like this one: class EmailClass { public string MailAdresse { get; set; } public string MailAdresseCC { get; set; } } Through a JSON deserialization I obtain a ...
0
votes
1answer
112 views

How to refactor sql query in a foreach

This is my code that works: foreach (var r in rlist) { if (r.IndexOf("_") != -1) { int id = int.Parse(r.Split('_')[1]); var x_tmp = (from x in db.tblX ...
3
votes
3answers
183 views

Keeping Linq's readability (e.g. over goto statements) without sacrificing performance

I'm doing Project Euler problem 5 as a kata, focussing on TDD and code readability. The challenge is: What is the smallest positive number that is evenly divisible by all of the numbers from 1 to ...
5
votes
5answers
172 views

Group collections by their elements property

I have a customer class: public class Customer { public Guid Id { get; set; } // Some other properties...} And a three transactions classes that have a reference to customer, like: public ...
1
vote
3answers
98 views

Can someone improve this code?

public bool CheckPlace(string State, string City) { TestDataContext data = new TestDataContext(); bool IsKochi = new bool(); if (!string.IsNullOrEmpty(State) && ...
2
votes
1answer
67 views

Simple retrieving sessionId rows from indexed SQL column is slow

I have to select all the rows from a database table containing a defined (long)sessionId where the sessionId row is indexed. But it is slow, and since the code to access it is really simple, I'm ...
4
votes
2answers
143 views

Optimization code for checking if a list contains any element ID of another list

I have the following code: var sessionsWithError = SessionsFilteredByDate .Where(i => i.TrackerId > 0 && i.StatusId == 0) .Select(i => i.SessionId); var ...
7
votes
3answers
328 views

How to optimize this code to get a instant/better result instead of waiting at least 10 seconds every time?

I have the following code that unfortunately is really slow: private void FilterSessionByDate() { SessionsFilteredByDate = ...
1
vote
2answers
1k views

Search and Filter in MVC3 Razor I am using Linq, is there a better way to do this

Heres my Code and it works fine. I just dont like all the If else, what If I keep adding field to filter, its going to get messy. Ps: I am not using EF and cannot on this. Thanks. CONTROLLER CODE ...
2
votes
1answer
300 views

filter a collection in a PagedCollectionView

I have scenario wherein I have to filter a collection in a PagedCollectionView. The filter criteria are Name and status which are check boxes with Enabled and Disabled labels If Enabled is checked it ...
4
votes
0answers
290 views

Multiple repository calls or LINQ query

These two methods do the exact same thing (or at least they are supposed to!). They both pass a simple test based on a mock context. Neither has been exposed to any integrated testing yet. Would ...
2
votes
1answer
51 views

Converting 'list of Foo' into 'lists of Foo properties'

I'm looking at some code that goes a bit like this: class Foo { public int Frob; public int Frib; } class Bar { public Foo Left; public Foo Right; } public void ProcessBars(Bar[] bars) { ...
3
votes
2answers
133 views

Is there a better way to convert two-dimentional array to string?

For logging purposes, I need to output a double[,] to the log file. So I need to represent the array as a string. The following code gets the job done using basic C# 1 features, but I was wondering ...
5
votes
2answers
298 views

Is there a better way of writing this action method using Linq?

I have an ASP.Net MVC3 web application that displays a list of parts (A part is a simple entity with a number and a description). I have updated the action method to support filtering and paging: ...
2
votes
2answers
183 views

Filter out string sections

I have a helper method to clean up a string and remove pieces that I will be generating again. (defined by the "SpecialKey" Constants) but I've never been real happy with the code. Although I find it ...
2
votes
1answer
212 views

Optimize the DateTime filter

I have been trying to optimize the filtering process of a Collection based on the DateTime GeneratedOn property of Alert class. Below is the code block which filters the List by taking in From Date ...
1
vote
2answers
277 views

LINQ transforming hierachical data to flat list

The following code is pretty ugly. I suspect that there is a more functional and elegant way of achieving this result. var lines = new[]{ new{Head="A",Value="1"}, new{Head="",Value="2"}, ...
10
votes
3answers
2k views

Is the LINQ version faster than the foreach one?

Since I don't know how LINQ works under the hood, I can't decide what version is best to use in term of rapidity of execution. I've done some testing with my testing data (Point Cloud) but I can't see ...
1
vote
1answer
134 views

C# LINQ Solution

I'm writing am application that I've previously posted questions on here, but I'l looking for some more similar advice of possible. I am looking for how best to write my code, as I have a working ...
0
votes
2answers
81 views

many linq calls on collection

I hava a collection of schedules - EventSchedules. I want to select from this collection today, tomorrow and after tomorrow schedules. The day start from 06:00 and end 6:00 of next day. Examples: ...
4
votes
2answers
221 views

LINQ Query performance - how to go about improving THIS query?

I have written a module in my application that makes extensive use of Dynamic LINQ to produce linq/sql queries based on user interface selection. Currently, the linq-sql translation is resulting in ...
0
votes
1answer
286 views

My own implementation of Linq SelectMany extension method

What do you think of my own implementation of the extension method SelectMany? Motivating criticism is always welcome. public static IEnumerable<TResult> MySelectMany<T, TResult>(this ...
2
votes
1answer
520 views

Class with methods to retrieve data with Linq to sql

I think here is something wrong with code. I use a class with methods to get tenants from DB: public List<CrmTenant> GetAllTenants() { List<CrmTenant> tenantsList = new ...
1
vote
3answers
2k views

Joining two IEnumerable<T>. Any better way to write this in LINQ?

I'm trying to merge two nodes. Basically, the idea is to take all children in left and new ones in right. Is there any way to get rid of toAdd variable and do it in a clean way? I don't want to ...
5
votes
1answer
295 views

This LINQ Model Query seems extremely inefficient

I'm new to LINQ, but I have some background in T-SQL. I know there are probably 100 different ways to design a T-SQL statement that would run this much more efficiently, but I'm not sure how I would ...
3
votes
3answers
156 views

Use linq to compute length of line defined as array of points

I have an array of points: Point[] line; // { Point(1,1), Point(2,3), Point(1,1) } Assuming Point has the relevant operators, what's the most linq-y way of computing the length of this line? My ...
1
vote
1answer
129 views

Simplify a complex LINQ query

Any suggestions how I could simplify this LINQ query? from type in assembly.GetTypes() where type.IsPublic && !type.IsSealed && type.IsClass where (from method in type.GetMethods() ...
3
votes
4answers
314 views

Alternative way to extract the most recent file using LINQ

All, I have written some code to get the latest files from a directory, the files I am looking for contain the string sProcScript = "sProcScript" and in the selected directory I might have several ...

1 2 3