I tried searching Google and this site for this, but it was hard to find the correct so this may ahve already been asked and answered somewhere, but I couldn't find it.
Anyway, I inherited some code for storing documents in a SQL 2005 database using the image datatype to hold the documents. We have a LINQ method that queries the table returning all of the columns including the document column potentially making this a very expensive operation, especially since we never use the document column on the client side when using this method.
Here's a snippet of the current code:
rtnList = (from c in pdc.View_ActiveDocumentRepositories
select new Document(c.ItemId, c.DocumentId, c.Extentsion, c.Filename, c.Document.ToArray(),
c.ModifiedDate, c.ModifiedBy, dSvc.GetStatus(c.Status), c.ApprovedDate, c.ApprovedBy,
c.Active)).ToList();
In order to reduce the load of this method I'd like to ignore the Document column. I can see a few methods:
Any thoughts as to the best answer? Thanks.
If pdc.View_ActiveDocumentRepositories
returns IQueryable
removing the Document from the select new
should remove it from the generated select clause.
(I say 'should' because obviously I can't see what's going on in the repository).
Drawback of this approach is that you have to think of leaving out the BLOB every time you query against this repository. We could start a long discussion on exposing IQueryable by repositories, but in short, I would let your repository have a dedicated method for retrieving 'lightweight' document objects.