Quale sarebbe il modo migliore per ottenere tutti i prodotti in tutte le categorie secondarie di una categoria principale selezionata? Cercando di ottenere 10000 prodotti in circa 80 categorie figlio, ma questo metodo è troppo lento. Eventuali suggerimenti? utilizzando C# e LINQ to SQLDa Linq a SQL C# Ottieni prodotti in tutti i child/sub child Categorie troppo lenti
//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 circa 6 secondi per restituire i risultati
hai gli indici appropriati? è questa entità framework o linq to sql? –
sei autorizzato a cambiare IDCase da varchar a int? –
yeah Gli indici ci sono. È Linq to SQL. ID della categoria è int ma accetta null. L'ID genitore delle categorie principali è nullo THanks – vts