首页 > 解决方案 > 在内部查询中使用子查询时,在外部查询中声明的变量变得无法访问其中的内部查询

问题描述

我的项目在嵌套查询中使用了子查询。在内部查询中使用子查询时,在外部查询中声明的变量变得无法访问其中的内部查询。调试嵌套查询时发现错误:1. 'field list' 中的未知列 'Join3.appcategoryid' 2. 'where 子句'中的未知列 'Extent1.taxonomyid'

enter code here :
public static dynamic GetTaxonomies
(int businessUnitId, int memberId, string businessUnitType)
        {
            using (var db = new ProtocolManagementDatabaseEntities())
            {
                var taxonomies = (from taxonomy in db.taxonomies
                                  join businessUnitTaxonomy in db.businessunittaxonomies on taxonomy.taxonomyid equals businessUnitTaxonomy.taxonomyid
                                  let TaxonomyID = taxonomy.taxonomyid
                                  where businessUnitTaxonomy.businessunitid == businessUnitId
                                  select new
                                  {
                                      TaxonomyId = taxonomy.taxonomyid,
                                      TaxonomyName = taxonomy.taxonomyname,
                                      preferenceValue = db.userpreferences.Where(x => x.entitycolumnvalue == TaxonomyID &&
                                      x.memberid == memberId && x.entitytablename == "Taxonomy" && x.sequencenumber == 5)
                                      .Select(x => x.isvisible).FirstOrDefault()

                                      AppCategory = (from appCategory in db.appcategories
                                                     join appCategoryTaxonomy in db.appcategorytaxonomies on appCategory.appcategoryid equals appCategoryTaxonomy.appcategoryid
                                                     let AppCategoryID = appCategory.appcategoryid
                                                     where appCategory.parentappcategoryid == null &&
                                                     appCategory.appcategorylevel.Equals("AppCategoryName")
                                                     && appCategoryTaxonomy.taxonomyid == TaxonomyID &&
                                                     appCategoryTaxonomy.businessunitid == businessUnitId

                                                     orderby appCategory.name ascending
                                                     select new
                                                     {
                                                         AppCategoryId = appCategory.appcategoryid,
                                                         AppCategoryName = appCategory.name,

                                                         AppCategoryDeletionEnable = db.appcategories.Where(x => x.parentappcategoryid == AppCategoryID)
                                                         .FirstOrDefault() != null ? true : false

                                                         SubCategory = from subCategory in db.appcategories
                                                                       let SubCategoryID = db.appcategories.Where(x => x.appcategoryid == subCategory.appcategoryid).Select(x => x.appcategoryid).FirstOrDefault()
                                                                       where subCategory.parentappcategoryid == AppCategoryID && subCategory.businessunitid == businessUnitId
                                                                       orderby subCategory.name ascending
                                                                       select new
                                                                       {
                                                                           AppCategoryId = subCategory.appcategoryid,
                                                                           AppCategoryName = subCategory.name,
                                                                           Description = subCategory.description,
                                                                           IsGlobal = subCategory.isglobal,
                                                                           IsEnable = subCategory.isenable,
                                                                           ParentAppCategoryID = appCategory.parentappcategoryid,
                                                                                   SubCategoryDeleteEnable = db.protocolappcategories.Where(x => x.appcategoryid == SubCategoryID)
                                                                           .FirstOrDefault() != null ? true : false,

                                                                           AppCategoryLevel = subCategory.appcategorylevel,
                                                                           IsExpand = false,
                                                                       }
                                                    }).ToList()
                                  }).ToList();
                return taxonomies;
            }
        }

标签: c#linq

解决方案


推荐阅读