I have a complicated query that select from many entity from database. but i'm facing a performance issue. the data takes a long time until it retrieved unlike the sql it takes only seconds.
Tables:
Product
productPrice (it contains more than 20k rows)
Category
Store
the query:
var grid = from p in db.Products.ToList()
from productPrice in db.ProductPrices.ToList()
where p.ProductID == productPrice.ProductID
from c in db.Categories.ToList()
where c.CategoryID == p.ProductCategoryID
where c.CategoryID == subCategoryID
from u in db.Users.ToList()
where u.UserID == productPrice.UserID
where u.UserID == storeID
select new
{
ProductID = p.ProductID,
StoreName = u.Name,
ProductCateogry = c.CategoryName,
CategoryHsCode = c.CategoryHsCode,
ProductName = p.ProductName,
ProductBarcode = p.ProductBarcode,
Price = productPrice.Price,
PriceUnit = productPrice.Unit,
LoggedDate = productPrice.LoggedDate
};
is there any problem with the query or entity frame work select all data then it filters it?