LINQ to return only header items where line items are not zero

I have a simple sales header / sales line item table and I would like to return all header items where there the total quantity of line items is not zero I thought I could just do a join but that returns the header items duplicated for each line item: var orders = from so… Read More LINQ to return only header items where line items are not zero

How can I list classes with similar IDs in a list with Linq?

I have NodeViewModel class. There is ID variable in NodeViewModel class. It can be two classes but with the same ID variable. IDs are not sequential numbers. Example ID; 010105. I have a list containing my NodeViewModels as follows; List<NodeViewModel> nodes = new List<NodeViewModel>((IEnumerable<NodeViewModel>)diagram.Nodes); It is necessary to export the information in the content of… Read More How can I list classes with similar IDs in a list with Linq?

Cannot convert expression type 'System.Linq.IQueryable to return type 'System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable

I’m trying to join 2 tables and return data that meet a specific condition. However, I get this error instead Cannot convert expression type ‘System.Linq.IQueryable<TicketBooking.Data.DataModel.Flight>’ to return type ‘System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<TicketBooking.Data.DataModel.Flight>>’ Here is the red squiggle error code, my intention is to return the flight that has the specific date. public async Task<IEnumerable<Flight>> GetFlightByDate(DateTime date) { var… Read More Cannot convert expression type 'System.Linq.IQueryable to return type 'System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable

Using Linq (not Lambda), how do I check if a list is empty and if it's not, return results contained in that list. Otherwise, return all results

I have an optional parameter called UserId. If UserId is passed in, I get a list of stores that are related to that User. If UserId is "", I get every store. public void Example(userId = ""){ var usersStores = new List<short>(); if(userId != "") userStores = GetStores(userId); var query = from t in _dbContext.FakeTable… Read More Using Linq (not Lambda), how do I check if a list is empty and if it's not, return results contained in that list. Otherwise, return all results

Problem using System.Linq to print a file line by line (C#)

So I’m writing a very simple way to display graphics content in a text file (Just unicode symbols) line by line, at a certain distance from the console edge. GraphicsDraw: int GraphicsDrawCount = 0; do { Console.SetCursorPosition(3, 3 + GraphicsDrawCount); TempMemory = Convert.ToString(File .ReadLines("F:\\Assets\\StartScreen.txt") .Skip(GraphicsDrawCount) .Take(1)+""); Console.WriteLine(TempMemory); GraphicsDrawCount++; } while (GraphicsDrawCount < 19); I expected… Read More Problem using System.Linq to print a file line by line (C#)

How to Read Lines from File and Turn Array of Strings into Dictionary in C# with line Number as Key?

I’m trying to read lines from a file (whose size is unknown) and convert the array values that start with "A" into a Dictionary with the line number as the key and the line contents as the value. I’m trying to think of a way of doing this without iterating over the array as that… Read More How to Read Lines from File and Turn Array of Strings into Dictionary in C# with line Number as Key?

What is the relation between the IEnumerable produced by LINQ and the original list?

I have the following lines of code: var list = new List<Test>() { new Test("Test1"), new Test("Test2") }; var enumerable = list.Where(t => t.Content == "Test1"); Console.WriteLine($"Enumerable count: {enumerable.Count()}"); Console.WriteLine($"List count: {list.Count}"); list.RemoveAll(t => t.Content == "Test1"); Console.WriteLine($"Enumerable count: {enumerable.Count()}"); Console.WriteLine($"List count: {list.Count}"); I would expect the output to be Enumerable count: 1 List count:… Read More What is the relation between the IEnumerable produced by LINQ and the original list?