¿Cuál sería la mejor manera de obtener todos los productos en todas las categorías secundarias de una categoría principal seleccionada? Intentando obtener 10000 productos en aproximadamente 80 categorías de niños, pero este método es demasiado lento. ¿Alguna sugerencia? usando C# y LINQ to SQLLinq a SQL C# Obtenga productos en todas las categorías secundarias/secundarias demasiado lentas
//list for the child categories
private List<int> catsChildList = new List<int>();
GetChildCats(123);
//get all the child categories of main category '123'
private void GetChildCats(int _parentCat)
{
var cats = (from c in db2.tbl_cart_categories
where c.ParentID == _parentCat
select new { c.CategoryID });
if (cats.Count() > 0)
{
foreach (var cat in cats)
{
int _cat = Convert.ToInt32(cat.CategoryID);
catsChildList.Add(_cat);
GetChildCats(_cat);
}
}
}
//Get the products
var products = (from p in db2.products_infos
where p.IsEnabled == true
group p by p.ProdID
into g where g.Any(x => catsChildList.Contains(Convert.ToInt32(x.CategoryID)))
dura aproximadamente 6 segundos para devolver resultados
¿tiene los índices apropiados? es este marco de entidad o linq a sql? –
¿está permitido cambiar CategoryID de varchar a int? –
sí, los índices están ahí. Es Linq a SQL. CategoryID es int pero acepta nulo. El ID principal de las categorías principales es nulo THanks – vts