[Solved] System.Linq.Expression.Compile error

Resolved. The method was called recursively, creating the parameter and the expression and returned to himself. In this process the parameters were removed from memory, as they had already been used believed not to have problems. But they need to be kept in memory until the time of compilation. In this case I used a … Read more

[Solved] How to convert this code to LINQ [closed]

The other answers have shown how you can (and should, IMO) do this without LINQ – but they’ve both still got the same problem that your original code does: you’re only checking whether the data set has any tables – it could have fewer than tableNo tables. I would suggest: public bool IsNullOrEmptyDataTable(DataSet objDataset, int … Read more

[Solved] Is there a stricter version of .Single()? [closed]

Single() already throws an InvalidOperationException if the result contains more than one element (or if it is empty). You were probably confusing it with First(), which doesn’t throw if there is more than one element. 2 solved Is there a stricter version of .Single()? [closed]

[Solved] Linq query conversion from C# To VB:NET

I’m not sure if this is what you need(it’s a random shot since your question is not complete): Dim orderedData = From d In collezione Order By d.Gruppo Group d By d.Gruppo Into g = Group From d In g Select New With { .withChildren = {d}. Union(g.Where(Function(c) c.Owner = d.Comp)) } Dim result = … Read more

[Solved] Linq: help me to make this work

You should group all person skills by person id, and then select only those groups, which contain both given category and sub category: unitOfWork.PersonSkillsRepository.GetAll() .GroupBy(p => p.PersonId) .Where(g => g.Any(p => p.IdCategory == ids.IdCategory) && g.Any(p => p.IdSubCategory == ids.IdSubCategory)) .Select(g => g.Key) For optimization, you can filter out skills which do not match any … Read more

[Solved] With an array of strings of equal length, get the nth character of each string in it’s own array using LINQ

A quick test shows that setting @jdweng’s purely LINQ solution 1X, a solution somewhat abusing LINQ to do indexing comes in at 7.4X and a solution using for comes in at 28.4X. (Ab)using LINQ with indexing: var c = Enumerable.Range(0, source[0].Length).Select(chpos => Enumerable.Range(0, source.Length).Select(si => source[si][chpos]).Join()).ToArray(); Using nested for loops: var sourcelen = source.Length; var … Read more

[Solved] Sort a Linq query

Start by breaking up your logic into separate operations rather than trying to write everything in one line. Compilers are smart cookies so they optimize things quite well, there’s no point making your code harder to read/understand: var facultySpecialties = specialty.faculty_specialties .Where(fs => fs.faculty.active) .ToList(); // Executes the query to retrieve faculty specialties. foreach(var facultySpecialty … Read more

[Solved] Find if string is in other string

I think you are looking for something like this class Program { static void Main(string[] args) { string attrs = “AAA,BBB,CCC,DDD”; List<Vehicle> vehiclesSort = new List<Vehicle>(); vehiclesSort.Add(new Vehicle(attrs)); vehiclesSort.Add(new Vehicle(“bbb”)); vehiclesSort = vehiclesSort.Where(o => o.attr.Contains(attrs)).ToList(); foreach (var VARIABLE in vehiclesSort) { Console.WriteLine(VARIABLE.attr); } } } public class Vehicle { public Vehicle(string attr1) { this.attr = … Read more