English 中文(简体)
LINQ2SQL选择订单和天空/摄入
原标题:LINQ2SQL select orders and skip/take

我的职能是从桌上订购,但并非全部。 它的ski(Page* Rows on page)和带(Rows on page)。 但存在非常大的问题(见Linq2SqlProfiler)。

  • If i open 1 page (Skip = 0, Take = 50) i have execution time: 150ms.
  • If i open 2 page (Skip = 50, Take = 50) i have execution time: 205ms.
  • ...
  • If i open 10 page (Skip = 450, Take = 50) i have execution time: 1005ms.
  • If i open 15 page (Skip = 700, Take = 50) i have execution time: 1700ms!

    public IEnumerable<Order> GetAllConfirmedOrders(DateTime firstDay, int? ProviderId = null, Guid? ManagerId = null, DateTime? date1 = null, DateTime? date2 = null, int iSkip = 0, int iTake = 50)
    {
        var predicate_order = PredicateBuilder.True<Order>();
        var predicate_orderlist = PredicateBuilder.True<OrderList>();
    
        if (ProviderId != null) predicate_orderlist = predicate_orderlist.And<OrderList>(ol => ol.ProviderAn == ProviderId);
        if (ManagerId != null) predicate_order = predicate_order.And<Order>(o => o.UserId == ManagerId);
        if (date1 != null && date2 != null) predicate_order = predicate_order.And<Order>(o => o.DateAdd >= date1 && o.DateAdd <= date2);
        else predicate_order = predicate_order.And<Order>(o => o.DateAdd >= firstDay);
    
        var orders = (from o in _dataContext.Orders
                      join ol in _dataContext.OrderLists.Where(predicate_orderlist) on o.Analit equals ol.OrderAn
                      where o.Status == 1
                      orderby o.DateAdd descending
                      select o).Where(predicate_order).Skip(iSkip).Take(iTake);
    
        return orders;
    }
    

产生了q状:

WHERE  [t2].[ROW_NUMBER] BETWEEN 50 /* @p2 */ + 1 AND 50 /* @p2 */ + 50 /* @p3 */
ORDER  BY [t2].[ROW_NUMBER]

WHERE  [t2].[ROW_NUMBER] BETWEEN 450 /* @p2 */ + 1 AND 450 /* @p2 */ + 50 /* @p3 */
ORDER  BY [t2].[ROW_NUMBER]

WHERE  [t2].[ROW_NUMBER] BETWEEN 700 /* @p2 */ + 1 AND 700 /* @p2 */ + 50 /* @p3 */
ORDER  BY [t2].[ROW_NUMBER]

它是否真的正常? 是否有办法节省近100-200米的执行时间?

问题回答

在检查你提供的样本执行时间之后,随着你打开更多的页数,它看上去的是线性增加(150->200->......->1005-> 1700)。 因此,到那时,你到达第15页,询问必须处理更多的记录,以收集与第15页对应的数据。 我的猜测不是第15页的问题,而是整个问题,随着记录数量的增加,问题本身的时间正在增加。 你可以尝试通过调整表格的索引来优化询问。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签