So what I want to do is have an api that gets a couple of columns from a big database, and returns them as CSV (text). The problem arises if i try to first get them, then build the csv, because the memory fills up quickly (400mb for 800k rows). This is the closest I've gotten to getting it to work, but The format isn't really CSV, It's rows separated by Quotes, and it isn't a single string.
public IEnumerable<string> getCSV()
{
var names = typeof(AddressBook).GetProperties()
.Select(property => property.Name)
.ToArray();
yield return string.Join(",", names);
foreach( string name in names)
var query = context.AddressBook.Select(x => string.Join(",", x.Name, x.Surname, x.BirthDate)).AsNoTracking();
foreach (string row in query)
{
yield return row;
}
}
MemoryOutOfBounds
exception.