LINQ结果到对象类非常慢 [英] LINQ result to object class very slow

查看:105
本文介绍了LINQ结果到对象类非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在学习Silverlight.到目前为止,一切都很好.现在,我正在构建一个小型的Silverlight应用程序,该应用程序使用Web服务从MSSQL数据库获取数据.

服务通过LINQ获取数据,将其放入结果中,然后将结果放入具有对象类的列表中.这个想法是将列表返回并绑定到数据网格.

结果的数据非常大(9369条记录).服务挂起(超时),同时使该列表返回.

如何加快速度?

Hi all,

I''m learning Silverlight. So far, so good. Now I''m building a small Silverlight application that uses webservices to get data from a MSSQL database.

The services gets the data through LINQ, puts it in a result and puts that result in a list with a object class. The idea is that the list is returned and bound to a datagrid.

The data, of the result, is a very large one (9369 records). The service hangs (timeout) while making that list to return.

How can I speed up things?

Thanks in advance.

推荐答案

不要运行将9369条记录返回到数据网格的查询吗?

不,严重:不要运行将9369条记录返回到数据网格的查询.

您希望用户如何处理?您认为他会花多长时间滚动浏览,然后再确定您的软件是垃圾,然后转移到其他地方?

对其进行分页-大约20条记录是正常的.允许他搜索它.过滤它.如果需要,请保存它.但是,不要只是将其丢弃在网格中然后走开!
Don''t run a query that returns 9369 records to a datagrid?

No, seriously: don''t run a query that returns 9369 records to a datagrid.

What do you expect the user to do with that? How long do you think he is going to spend scrolling through before he decides your software is a load of rubbish and goes elsewhere?

Page it - about 20 records is normal. Allow him to search it. Filter it. Save it if you must. But don''t just dump it in a grid and walk away!


使用LINQPad验证您的请求: http ://www.linqpad.net/ [ ^ ].

使用该工具,您将了解如何将请求转换为SQL及其所需的时间.

数据来自单个表还是多个表?如果它来自多个表,那么首先要检查的是查看是否对服务器进行了很多往返操作.

对于大型表而言,有效的方法是必须使用分页或虚拟加载数据.
Verify your request with LINQPad: http://www.linqpad.net/[^].

Using that tool, you will have an idea how your request is translated into SQL and the time it takes.

Does the data come from a single table or multiple tables? If it come from multiple tables, the first thing to check would be to see if lot of round-trip are made to the server.

And effectively for large tables, you have to uses paging or virtual loading of the data.


我第二次建议不要使用分页来返回9369条记录.但是,除非查询非常简单,否则我一般不会使用LINQ来访问SQL DB.如果可以直接控制自动生成的内容,请不要使用.
I second the advice to no return 9369 records, use paging. However, I would not use LINQ to access a SQL DB in general, unless your query is incredibly simple. Never use auto generated stuff if you can control it more directly.


这篇关于LINQ结果到对象类非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆