任何方式使這更高效?有什麼辦法可以提高效率?它運行速度很快,只是想改善,如果可用
internal Func<enntities, IQueryable<CategoryList>> GetCategoryListWithPostingCount =
CompiledQuery.Compile((entities entities) =>
from c in entities.Categories.Include("Postings_Categories")
where c.ParentCategoryID == null
orderby c.DisplayOrder
select new CategoryList
{
ParentCategoryName = c.CategoryName,
ParentCategoryID = c.CategoryID,
SubCategories = (
from s in entities.Categories
where s.ParentCategoryID == c.CategoryID
select new SubCategoryList
{
PostingCount = s.Postings_Categories.Count,
SubCategoryName = s.CategoryName,
SubCategoryID = s.CategoryID
})
});
它產生什麼SQL?你看到什麼查詢計劃?你有什麼指數?在這個細節層面上,這個問題很難回答。 – spender 2011-03-08 00:15:58
如果它已經運行得很快,那麼我認爲這可能是[過早優化](http://en.wikipedia.org/wiki/Program_optimization#When_to_optimize)的例子。 – srgerg 2011-03-08 00:17:04