嗨,我刚刚发现我的 Web 应用程序很慢,可能是因为 linq。
我对那些编译的查询有点迷茫,你能帮我编译一个查询并让它仍然可以用来查询查询吗?(这可以理解吗?:p)例如这个查询(在 vb.net 中):
Dim query = (From p In db.ProductCategories _
Group Join t In db.Translate_ProductCategories On p.ID_Category Equals t.Category_ID Into res = Group From r1 In res.DefaultIfEmpty _
Where r1.Language_ID = langID And p.CategoryActive = True _
Select New With {.name = r1.Name, .idcat = p.ID_Category, .level = p.CategoryLevel, .index = p.CategoryIndex, .parentID = p.CategoryParent_ID})
然后我想确保仍然能够做这样的事情:
Dim level0 = (From l In query Where l.level = 0 Order By l.index Ascending Select l)
谢谢您的帮助
编辑:
我试着这样做:
Dim myquery = CompiledQuery.Compile( _
Function(db As EshopDataContext) _
(From p In db.ProductCategories _
Group Join t In db.Translate_ProductCategories On p.ID_Category Equals t.Category_ID Into res = Group From r1 In res.DefaultIfEmpty _
Where r1.Language_ID = langID And p.CategoryActive = True _
Select New With {.name = r1.Name, .idcat = p.ID_Category, .level = p.CategoryLevel, .index = p.CategoryIndex, .parentID = p.CategoryParent_ID}))
Dim query = myquery.Invoke(db)
Dim level0 = (From l In query Where l.level = 0 Order By l.index Ascending Select l)
我有错误“查询结果不能被枚举多次。” 在这条线上
cptCat1 = level1.Where(Function(l1) l1.parentID = parentId1).Count