score:2
Why not write the file directly? Use foreach
on the IQueryable
, and write out a CSV file row by row.
score:1
CSV might not be the best solution. I work with very large data sets all the time and use a function similar to this. I'm going to assume if it's IQueryable it is also IEnumerable. Here is the sample code, do with it what you like. If the delimiter is "," then it will output a CSV and if the delimiter is a "\t" you will output an Excel readable file. Either way you will need to do something similar to output a one line header containing the column titles before you run this method to output the data.
//This is changed slightly from my actual code but it should give you an idea of what to do
//tickStorage contains a dictionary named MessageData and the key is the column name
//Obviously tickStorage is what is being directly mapped to my listView component
private void OutputItems(StreamWriter writer, int startIndex, int endIndex, String delimiter)
{
endIndex = endIndex < tickStorage.Count ? endIndex : tickStorage.Count;
for (Int32 i = startIndex; i < endIndex; i++)
{
IEnumerator<Columns> fields = listView.ColumnsInDisplayOrder.GetEnumerator();
fields.MoveNext();
writer.Write((tickStorage[i].MessageData[fields.Current.Text]).Trim());
while (fields.MoveNext())
{
writer.Write(delimiter + (tickStorage[i].MessageData[fields.Current.Text]).Trim());
}
writer.WriteLine();
}
}
Source: stackoverflow.com
Related Articles
- Export an IQueryable Collection to Excel
- This code returns distinct values. However, what I want is to return a strongly typed collection as opposed to an anonymous type
- Some data is missing in the Export to Excel using DataTable and Linq
- Trying to change properties of an IQueryable collection
- LINQ WHERE method alters source collection
- Execute expression on another IQueryable source
- LINQ Source Code Available
- C# Code Contracts -- How to ensure that a collection of items contains items with unique properties?
- .NET 4 Code Contracts: "requires unproven: source != null"
- How to export linq result to excel just like Linqpad
- Unit testing code using IQueryable
- creating Linq to sqlite dbml from DbLinq source code
- EPPlus Excel Export - All data values going into Column A for each record?
- export to excel give me checkbox instead of string
- IQueryable collection lazy property setting on object
- Cannot build the Test project for LINQ IQueryable Toolkit (IQToolkit) - Code 9009
- EF Code first - add collection to a collection, appropriate usage of skip() and take()
- source code for LINQ 101 samples
- Export to Excel - How to dynamically set header text using LINQ?
- Export to Excel - LINQ - Include ForeignKey values in .ToList()?
- LINQ where clause using Generic IQueryable source
- Simple LINQ join to return IQueryable collection of objects
- Using IQueryable Filtering on a custom collection
- c# - Export large object data to Excel file
- How to export data to Excel using ASP.NET MVC 5 without reloading the page?
- How to export data to excel in C# using Linq
- Optimize IQueryable query to let EF generate a single SQL query instead multiple. Child collection of an entity must contains a custom collection
- How to use Linq or Lambda with IQueryable to GroupBy and get the first/last record on the collection in C#?
- List or Array of String Contain specific word in Html Source Code
- IQueryable<OFSOMEOBJECT> Export to excel
- Read distinct values from CSV to Datagridview in C#
- Linq Expression to select items based on list
- Special nested query in LINQ
- Apply search patterns in Where method?
- C#: Search a list of defined queryable fields, different per model, with linq through generics (using entity framework)
- Linq multiple left outer joins with grouping
- C# Linq how to select all columns except one (DateTime)?
- LINQ query returns way more results than in the entire database
- Setting a variable to linq query with no results
- Sql order by < string in linq to entity framework
- Passing Parameters from View to Action in MVC
- 2 similar LINQ statements with different syntax yielding different output
- How to select Distinct names from a xml database using LINQ?
- selecting a column values from a Table using LINQ (Entity Framework)
- how to get multiple result sets using linq
- Check if string exists in list of strings in C#
- Is it possible to join an unrelated table in an EF Core Include query
- Not Getting Updated data when using threading
- The Include path expression must refer to a navigation property defined on the type.
- linq join tables with multiple columns with or condition