如何通过 LINQ 处理图像数据类型
我尝试在谷歌和这个网站上搜索这个问题,但是很难找到正确的,所以这可能已经在某个地方被问过并得到了回答,但我找不到它。
不管怎样,我继承了一些用于在 SQL 2005 数据库中存储文档的代码,使用图像数据类型来保存文档。我们有一个 LINQ 方法,它查询返回所有列(包括文档列)的表,这可能会导致成本非常昂贵,特别是因为我们在使用此方法时从不在客户端使用文档列。
以下是当前代码的片段:
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();
为了减少此方法的负载,我想忽略 Document 列。我可以看到一些方法:
- 删除对 Document 列的引用(这是否有效,或者数据是否会通过 ActiveDocumentRepositories 对象返回,即使它未使用)?
- 创建一个要使用的新视图,不包括“文档”列。
- 不包括文档列的存储过程。 (不过应该与#2 相同。)
对于最佳答案有什么想法吗?谢谢。
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:
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
pdc.View_ActiveDocumentRepositories
返回IQueryable
,从select new
中删除文档应该将其从生成的select子句中删除。(我说“应该”是因为显然我看不到存储库中发生了什么)。
这种方法的缺点是每次查询此存储库时都必须考虑忽略 BLOB。我们可以开始关于通过存储库公开 IQueryable 的长时间讨论,但简而言之,我会让您的存储库有一个专门的方法来检索“轻量级”文档对象。
If
pdc.View_ActiveDocumentRepositories
returnsIQueryable
removing the Document from theselect 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.