c# - 在内部查询中使用子查询时,在外部查询中声明的变量变得无法访问其中的内部查询
问题描述
我的项目在嵌套查询中使用了子查询。在内部查询中使用子查询时,在外部查询中声明的变量变得无法访问其中的内部查询。调试嵌套查询时发现错误: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;
}
}
解决方案
推荐阅读
- django - Django 正确的 url 路径,但找不到页面 url 不匹配
- c# - “无法翻译 LINQ 表达式”与 LINQ 查询中的 DateTime 比较?
- javascript - React JS - 从外部属性文件中读取配置?
- google-my-business-api - Google My Business Api 格式化帖子问题
- gitlab - 如何在 gitlab 的 autodevops 中跳过生产部署
- django - "non_field_errors": [ "无效数据。需要字典,但得到了列表。" ] 在 django rest 框架中,同时在 postman 中调用 api
- php - Laravel 获得两个对象之间的联合
- python - 调试 .pyz 可执行文件
- azure - 使用 Terraform Azure 的多个 VM 和磁盘
- css - 如何将 Vuetify 的 CSS 重置范围仅限于 VueJS 应用程序?