0

I am using EF6 to develop an application that uses a huge data,so in one of my query

his = db.HISTORies.ToList();
            front = db.Fronts.ToList();
            warehouses = db.Warehouses.ToList();
            //------
            var q =
                his.GroupBy(j => new { j.Line_Number_PGZ, j.MAT_0_PG,j.JOINT_NO_PGZ }).ToList().Select(m => new gridView()
                {
                    JointNumber = m.Key.JOINT_NO_PGZ,
                    material0 = m.Key.MAT_0_PGZ,material0Name =his.Where(i=>i.MAT_0_PGZ==m.Key.MAT_0_PGZ).First().Code_0_Object_PGZ,
                    line = m.Key.Line_Number_PGZ
                }).OrderByDescending(i => i.material0Need).ToList();

As you can see i fetch all my database to my application .so in my query i grouped my data based on 2 columns ,but my problem is the his has a lot of records so in this line

his.Where(i=>i.MAT_0_PGZ==m.Key.MAT_0_PGZ).First().Code_0_Object_PGZ

I again search an items in this table and this line makes my application to be so slow how can fix this query?

The Code_0_Object_PGZ is in his list but it can be accessed in the select statement !!!

I want to know how can i access Code_0_Object_PGZ without include it in groupby ?

best regards

Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180
  • 1
    Why do you load the whole database to memory? SQL storage is much better in this kind of operations than regular LINQ methods. Use LINQ to Entities until you have all the required information and only then load the results into memory. – galenus Nov 02 '14 at 12:28
  • Because i need all information so i have to load all of them – Ehsan Akbar Nov 02 '14 at 12:31
  • That's OK, but all the operations you perform, such as GroupBy and Where are much more efficient when they are performed by SQL. Try and see the difference. You can load the results prepared by SQL. – galenus Nov 02 '14 at 12:38

0 Answers0