How to handle image datatype through LINQ
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.V开发者_Python百科iew_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:
- Remove the reference to the Document column (will this work or will the data be returned through the ActiveDocumentRepositories object even though it's not used)?
- Create a new view to use that excludes the Document column.
- Stored procedure that excludes the Document column. (Should be the same as #2, though.)
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.
精彩评论