加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – ASP.NET和EF非常慢

发布时间:2020-12-15 23:43:21 所属栏目:百科 来源:网络整理
导读:通过使用EF,C#和ASP.NET 4 Web应用程序,我使用以下代码从数据库中检索数据并填充GridView: using (AshModel am = this.conn.GetContext()){ IEnumerableArticle articles = (from a in am.Article.AsEnumerable() where (a.CultureName == calture || a.Cul
通过使用EF,C#和ASP.NET 4 Web应用程序,我使用以下代码从数据库中检索数据并填充GridView:

using (AshModel am = this.conn.GetContext())
{
    IEnumerable<Article> articles = 
        (from a in am.Article.AsEnumerable()
         where (a.CultureName == calture || a.CultureName == 0)
             && a.IsApproved == status
             && a.IsPublished == status
         orderby a.AddedDate descending
         select a);

    IEnumerable<Profile> profiles = am.Profile.AsEnumerable()
        .Where(t => articles.Any(a => a.ProfileId == t.ProfileID));

    foreach (Article article in articles)
        article.UserProfile = profiles
            .Where(a => a.ProfileID == article.ProfileId)
            .FirstOrDefault();

    this.gvArticles.DataSource = articles.ToList();
    this.gvArticles.DataBind();
}

但它非常慢,响应大约需要2分钟,数据库中只有500条记录!我的错误是什么?我如何才能提高绩效?
谢谢.

解决方法

你在某些部分正在做AsEnumerable().

执行此操作时,将从数据库中检索所有对象,然后对其进行过滤.

如果你删除那些AsEnumerable()它应该按预期工作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读