LINQ到实体:计数速度很慢 [英] Linq to Entities : Count is very slow

查看:558
本文介绍了LINQ到实体:计数速度很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有家长和parent.child.count()......在查询..当我做到这一点正在20秒....它不是一个庞大的数据库...优化任何想法...

  VAR的plist = context.persons 
。选择(p =>新建
{
p.fullName,
c.personID,
p.Status,
p.Birthdate,
p.Accounts.Count
})了ToList( );


解决方案

下面是使用count一个伟大的文章()的时候你真的想用任何()



http://blogs.teamb.com/craigstuntz/2010/04/21/38598/


I need to have parent and parent.child.count()....in the query.. when i do this it is taking 20 seconds....its not a huge database...Any ideas for optimization...

var plist = context.persons
  .Select(p => new
  {
    p.fullName,
    c.personID,
    p.Status,
    p.Birthdate,
    p.Accounts.Count
  }).ToList();

解决方案

Here is a great article on using count() when you really meant to use any()

http://blogs.teamb.com/craigstuntz/2010/04/21/38598/

这篇关于LINQ到实体:计数速度很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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