I have an MVC application, which uses EntityFramework to connect to MS SQL Server 2012. I am trying to retrieve the total file size of all documents stored in the Documents table.
I am using the following code:
this.Documents.Sum(x => x.FileSize);
Where Documents is of type EntityCollection<Document>
. The operation is taking over 1.6 minutes to complete, at which point it crashes with
Exception of type 'System.OutOfMemoryException' was thrown.
Surely this is just the same as doing SELECT SUM(FileSize) FROM Documents
which takes just a few milliseconds to complete when executed directly via SQL Server Management Studio.
For what it's worth, the total size is 816mb, and includes 1,661 documents, so it's not exactly massive.