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 Query
- 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
More Query from same tag
- Is it possible to achieve/preserve deferred execution over WCF?
- Why is var Int32 not List<Int32> in this example
- Combining child class lists to parent class list
- LINQ Join Order By then Result Order By
- Generic expression for where clause - "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities."
- insert two object in database with linq
- How to use Linq To XML to get multiple elements and store them differently?
- Using LINQ to count values in a multiple join
- How to split string before Binding in repeater
- Casting errors when attempting to return an IQueryable<MyType>
- linq to entities cannot convert type Icollection to type List
- LINQ .Startswith or .Contains problems in VB.NET4
- Linq and entity framework distinct on non-primary key value
- Reordering different types of arrays with correspondence
- Order by descending by row field in query
- Is it possible to use .AsParallel Extension Method in PCL?
- Using "from in" in a LinqSpecs specification?
- How can I write a linq query to get blogId in mvc web application
- Can't figure out the right linq query for this
- Set Properties Inside Parameterless Constructor
- Polymorphic Associations in .NET
- How can I join datasets from multiple tables with only certain columns in EF Core?
- .NET C# I want to get the IDs (1/multiple) from a data if it much the ID of another table
- How do I know if my linq will return a useable object or a null
- LINQ Find all records where ID contains search term
- How do I use LINQ Contains(string[]) instead of Contains(string)
- NHibernate Overcoming NotSupportedException
- How do I segment the elements iterated over in a foreach loop
- Get index of parameter of element in list
- LINQ query on a custom DataTable