相关疑难解决方法(0)

linq to sql startwith performance索引列

我首先使用实体​​代码.索引列:

  • SourceCatalogId
  • CategoryPath

表中有40 000行,

我的问题是查询需要40s !!

var result = DBContext.Set<SourceProduct>()
            .Include(x => x.SalesHistories, x => x.SourceCatalog)
            .Where(p => p.SourceCatalogId == 2)
            .where(p => p.Disabled == false)
            .where(x => x.CategoryPath.StartsWith("MyPath"))
            .orderby(x => x.ShortDesignation)
            .Skip(1)
            .Take(10)
            .toList();
Run Code Online (Sandbox Code Playgroud)

SQL通过sql profiler:

exec sp_executesql N'SELECT TOP (10) 
[Project1].[SourceProductId] AS [SourceProductId], 
[Project1].[SourceSKU] AS [SourceSKU], 
[Project1].[SourceCatalogId] AS [SourceCatalogId], 
[Project1].[ManufacturerReference] AS [ManufacturerReference], 
[Project1].[Disabled] AS [Disabled], 
[Project1].[EAN] AS [EAN], 
[Project1].[ShortDesignation] AS [ShortDesignation], 
[Project1].[FullDesignation] AS [FullDesignation], 
[Project1].[Description] AS [Description], 
[Project1].[Url] AS [Url], 
[Project1].[CategoryPath] AS [CategoryPath], 
[Project1].[Condition] AS [Condition], …
Run Code Online (Sandbox Code Playgroud)

c# sql linq entity

6
推荐指数
1
解决办法
1856
查看次数

标签 统计

c# ×1

entity ×1

linq ×1

sql ×1