为什么使用 Entity Framework 获取数据很慢?

Why getting data with Entity Framwork is slow?

我正在使用 C# 和 Entity Framework 创建一个 Windows 表单程序。我想从SQL数据库中获取数据,获取后做一些处理。

一切都很好,但是性能太差了,即使数据很少,速度也太慢了。我的代码在下面,我想知道我的代码有什么问题。

我搜索了很多,但没有找到有用的东西。

提前致谢

private readonly BarForooEntities1 _barforoosh = new BarForooEntities1();

public void Getdataforoosh()
{
    BindingSource b = new BindingSource();

    b.DataSource = (from m in _barforoosh.RadifsSendCenter
                    where m.Receive == false
                    select new
                           {
                               m.id_rec, m.Radifkolsal,
                               m.Dates, m.DateErsal,
                               m.TimeErsal, m.Karkhane,
                               m.Namekala, m.Vazn,
                               m.Bandal, m.Dobaskul,
                               m.OldYear, m.Sal,
                               m.del, m.edit, m.Daryaft,
                               m.Shobe, m.Greid, m.TedadBas, 
                               m.Rahgiry, m.Tozih, m.NoeShemsh, 
                               m.Metrazh, m.Keyfiat, m.Address,
                               m.City, m.Karbar, m.CodeKala,
                               m.CodeGoruh, m.CodeKG, m.CodeGreid,
                               m.Tel, m.ShenaseMeli, m.Sefaresh,
                               m.Tolid, m.Shenase, }).ToList();
    dataGridView1.DataSource = b;

    for (int i = 0; i < dataGridView1.RowCount; i++)
    {
        int c = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value);

        var f = (from a in _barforoosh.RadifsSendCenter
                 where a.id_rec == c
                 select a).SingleOrDefault();
        f.Receive= true;
        _barforoosh.SaveChanges();
    }
}

SaveChanges 方法 放在 for 循环之外 :

for (int i = 0; i < dataGridView1.RowCount; i++)
{
}
_barforoosh.SaveChanges();