c# – ASP.NET和EF非常慢

c# – ASP.NET和EF非常慢,第1张

概述通过使用EF,C#和ASP.NET 4 Web应用程序,我使用以下代码从数据库中检索数据并填充GridView: using (AshModel am = this.conn.GetContext()){ IEnumerable<Article> articles = (from a in am.Article.AsEnumerable() where 通过使用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()它应该按预期工作.

总结

以上是内存溢出为你收集整理的c# – ASP.NET和EF非常慢全部内容,希望文章能够帮你解决c# – ASP.NET和EF非常慢所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1220756.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存