[Solved] How to change loop of nested lists linq

Avoiding the foreach will lose a small amount of performance and make the code harder to follow, but based on your (probably wrong) question, here is the equivalent LINQ: var ans = listL1.elements.SelectMany(level1 => level1.elements.SelectMany(level2 => listL2.elements.Select(level3 => new Level() { itemFromLevel1 = level1, itemFromLevel2 = level2, itemFromLevel3 = level3}))).ToList(); 2 solved How to change … Read more

[Solved] Linq and List of Lists

This is a pretty straightforward query: allDevices.Where(d => d.Options.Any(o => o.Name == “Foot Pedal” && o.Installed)); Remember that a lambda is just a function. It can call other functions, declare variables, and everything else you can do in normal code. solved Linq and List of Lists

[Solved] Linq and List of Lists

Introduction Linq and List of Lists is a powerful combination of technologies that can be used to create powerful and efficient data structures. Linq is a set of language-integrated query (LINQ) technologies that allow developers to query and manipulate data in a variety of ways. List of Lists is a data structure that allows for … Read more

[Solved] C# LINQ queries within queries and selecting groups

The first method should use this method: https://msdn.microsoft.com/en-us/library/vstudio/bb549393(v=vs.100).aspx Something like: return students.GroupBy(student => student.Level, (level, students) => new Tuple(level, students.Count())); Sorry I’m unable to test this, but basically like your version I’m using a lambda to say Group all students by level. The second lambda tells the method what to do with those groups. In … Read more

[Solved] How do I group the data received from SQL server

If you want to retrieve only some of the columns then use the following overload: var result = data.GroupBy(key => key.Role, element => element.DocumentType); Otherwise you can also use this projection: var result = data.GroupBy(key => key.Role) .Select(g => new { Role = g.Key, Documents = g.Select(i => i.DocumentType) }); 3 solved How do I … Read more

[Solved] Get Records count of specified date-range from database, if no record present for one of the date then return count as ‘0’

You should create some dummy data to fill in the gaps. Since you’re doing a Sum, you can just create some dummies of your input data. To do so, I’ve assumed that Set is List<SourceData> – change this as necessary: public class SourceData { public DateTime Date { get; set; } public long TotalHours { … Read more

[Solved] assign value to a field in a list using linq

Is this what you are looking for? public class Worker { public string Name {get;set;} public string CompanyId {get;set;} public string CompanyName {get;set;} } public class Company { public string Name {get;set;} public string Id {get;set;} } var companyList = new List<Company> { new Company{Id = “1”, Name = “Company 1”}, new Company{Id = “2”, … Read more

[Solved] LINQ with List

You want to use Any for that since l_obja is not a list of the ids. List<ClassA> l_obja = Obj1.exp.Values.Where(i => i.Id == mid).ToList(); List<ClassB> l_objb = Obj1.Pol.Values.Where(i => l_obja.Any(a => a.MGId == i.GId)); solved LINQ with List

[Solved] How to call a function in LinQ

First of all, this code is incorrect: List<users> userList = getUsers(); public class user { string Name; string Country; DateTime EnrollmentDate; } List<users> should be List<user>. Next to that, the Name, Country and EnrollmentDate should be marked public in order to be accessed. The same goes for the return type of the extract unQualifiedUsers-method (which … Read more