[Solved] Datatable to dictionary [closed]

Based on the additional information, the problem is that you are not passing the right arguments to ToDictionary. It takes two lambdas, not a lambda and a List<>. Here’s the first step to fixed code: dt.AsEnumerable().ToDictionary( dtRow => dtRow.Field<Int64>(“CodeVal_1”), dtRow => new List<string> { dtRow.Field<string>(“CodeVal_2”), dtRow.Field<string>(“CountryCode”) } ); EDIT: fixed using wrong version of ToDictionary. … Read more

[Solved] Translate to LINQ [closed]

Try this: return ( from div in strExport.Split(chrDivSep) from item in div.Split(chrItemSep) where String.Equals(item.Split(chrCoupleSep)[0], “table”, StringComparison.OrdinalIgnoreCase) ).Any(); solved Translate to LINQ [closed]

[Solved] Stable sort with OrderBy [closed]

you can order by the key like this : var ordered = lstValuesTemp.OrderBy(v => v.Key); or you can order with fonction declare the function like this: public static string CustomOrder(KeyValuePair<string, List<string>> item) { //TODO: add some logic that return a string to compare this item } and than call thia function: var ordered = lstValuesTemp.OrderBy(CustomOrder); … Read more

[Solved] What is LINQ in following code?

Your question show complete lack of effort to investigate the matter. LINQ = Language INtegrated Queries; It’s language construct that allows you to query objects / databases / other in a manner similar to SQL. Start by reading some guide like this 4 solved What is LINQ in following code?

[Solved] Can’t use Count() in C#

Your resource is not a list but an object. Better implementation would be something like this. [HttpGet(“{id}”)] public IActionResult Get(string id) { using (var unitOfWork = new UnitOfWork(_db)) { var r = unitOfWork.Resources.Get(id); if (r == null) { return NotFound(); } return Ok(ConvertResourceModel(r)); } } 0 solved Can’t use Count() in C#

[Solved] Removing at most one occurrence of an item from a list [closed]

How about: myList.RemoveAt(myList.indexOf(0)); And more generalized version would be: void RemoveFirst<T>(List<T> list, T item) { var indexOfItem = list.IndexOf(item); if(indexOfItem != -1) list.RemoveAt(indexOfItem); } Note: What .Remove() does shold be crystal clear to everyone. But when one wants to see the logic behind it, I think my answer still has some value. 14 solved Removing … Read more

[Solved] How to convert linq query to non-query expression?

If you want to convert this to the method syntax version, you can do this step by step. I like to start at the end and work through to the beginning: select to Select defines the source: .Select(g => g.OrderByDescending(s => s.MeasureDate).FirstOrDefault()); group is GroupBy: .GroupBy(s => s.SensorUnitId) .Select(g => g.OrderByDescending(s => s.MeasureDate).FirstOrDefault()); from the … Read more

[Solved] Evaluating equations during “new EXlement”

The locally scoped winTemp variable is hiding the instance variable (inside readXML() method). Thus winTemp instance variable does not get set at all and holds the default value, i.e. 0, by the time of addition. solved Evaluating equations during “new EXlement”

[Solved] Helping grouping by in LINQ [closed]

test this. foreach (var item in query_1.GroupBy(x=> x.Name).Select(x=> x.First())) { MultipleTableQueryResultVM objcvm = new MultipleTableQueryResultVM(); objcvm.firstName = item.Name; objcvm.CommerceTransID = item.TransID; objcvm.Type = item.Tipo; objcvm.Name = item.Nombre; VMList.Add(objcvm); } 1 solved Helping grouping by in LINQ [closed]

[Solved] Move duplicates of a list within the list c#

You need to add a property ( i called it Others) to Employee to store the list employees .GroupBy(x => x.EmpID) .Select(g => { var byPres = g.OrderByDescending(x => x.DateofPresentation).ToArray(); var e = byPres.First(); e.Others = byPres.Skip(1).ToList(); return e; }) see demo https://dotnetfiddle.net/kRiMds 0 solved Move duplicates of a list within the list c#