如何通过 LINQ 处理图像数据类型

发布于 2024-12-05 04:19:23 字数 786 浏览 1 评论 0原文

我尝试在谷歌和这个网站上搜索这个问题,但是很难找到正确的,所以这可能已经在某个地方被问过并得到了回答,但我找不到它。

不管怎样,我继承了一些用于在 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 列。我可以看到一些方法:

  1. 删除对 Document 列的引用(这是否有效,或者数据是否会通过 ActiveDocumentRepositories 对象返回,即使它未使用)?
  2. 创建一个要使用的新视图,不包括“文档”列。
  3. 不包括文档列的存储过程。 (不过应该与#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:

  1. 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)?
  2. Create a new view to use that excludes the Document column.
  3. Stored procedure that excludes the Document column. (Should be the same as #2, though.)

Any thoughts as to the best answer? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤感在游骋 2024-12-12 04:19:23

如果pdc.View_ActiveDocumentRepositories返回IQueryable,从select new中删除文档应该将其从生成的select子句中删除。

(我说“应该”是因为显然我看不到存储库中发生了什么)。

这种方法的缺点是每次查询此存储库时都必须考虑忽略 BLOB。我们可以开始关于通过存储库公开 IQueryable 的长时间讨论,但简而言之,我会让您的存储库有一个专门的方法来检索“轻量级”文档对象。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文