C# 类型1之间未定义强制运算符 var cpaclassids=FetchProductTypes(id); var cpaclids=string.Join(“,”,cpaclassids); var query=(从partJoinTableRepository.GetPartJoinQuery()中的x连接到partRepository.GetPartsQuery()中的y 在x.PartId上的partProductTypeReposiotry.GetPartProductTypesQuery()中加入z,其中y.IsSkiped==0&&&(y.IsDisabled!=“y”| | y.IsDisabled==null)&&z.CreatedDate==x.CreatedDate&&x.CreatedDate==Convert.ToDateTime(fromDate)选择new{x}).Cast(); var predicate1=PredicateBuilder.True(查询); predicate1=predicate1.And(x=>cpaclassids.Contains(x.ProductTypeId.ToString()); int lst=query.Where(谓词1).Select(x=>x.PartId).Distinct().ToList().Count();//在这条线上

C# 类型1之间未定义强制运算符 var cpaclassids=FetchProductTypes(id); var cpaclids=string.Join(“,”,cpaclassids); var query=(从partJoinTableRepository.GetPartJoinQuery()中的x连接到partRepository.GetPartsQuery()中的y 在x.PartId上的partProductTypeReposiotry.GetPartProductTypesQuery()中加入z,其中y.IsSkiped==0&&&(y.IsDisabled!=“y”| | y.IsDisabled==null)&&z.CreatedDate==x.CreatedDate&&x.CreatedDate==Convert.ToDateTime(fromDate)选择new{x}).Cast(); var predicate1=PredicateBuilder.True(查询); predicate1=predicate1.And(x=>cpaclassids.Contains(x.ProductTypeId.ToString()); int lst=query.Where(谓词1).Select(x=>x.PartId).Distinct().ToList().Count();//在这条线上,c#,C#,例外情况详情: 在类型“f_uAnonymousType5”1[PartDomain.Model.Models.PartJoinTable]和“PartDomain.Model.Models.PartJoinTable”之间未定义强制运算符 当我尝试获取lst中的计数时,将显示异常 var cpaclassids = FetchProductTypes(ids); var cpaclids = string.Join(",", cpaclassids); var q

例外情况详情:

在类型“f_uAnonymousType5”1[PartDomain.Model.Models.PartJoinTable]和“PartDomain.Model.Models.PartJoinTable”之间未定义强制运算符

当我尝试获取lst中的计数时,将显示异常

 var cpaclassids = FetchProductTypes(ids);
 var cpaclids = string.Join(",", cpaclassids);            
 var query = (from x in partJoinTableRepository.GetPartJoinQuery() join y in partRepository.GetPartsQuery() on x.PartId equals y.Id
                                      join z in partProductTypeReposiotry.GetPartProductTypesQuery() on x.PartId equals z.PartId where y.IsSkipped == 0 && (y.IsDisabled != "Y" || y.IsDisabled == null) && z.CreatedDate == x.CreatedDate && x.CreatedDate == Convert.ToDateTime(fromDate) select new { x }).Cast<PartJoinTable>();

 var predicate1 = PredicateBuilder.True(query);
 predicate1 = predicate1.And(x => cpaclassids.Contains(x.ProductTypeId.ToString()));

 int lst = query.Where(predicate1).Select(x => x.PartId).Distinct().ToList().Count(); // on this line
正在返回一个匿名类型,其
x
属性类型为
PartJoinTable
。正如预期的那样,该匿名类型无法转换为
PartJoinTable

解决方案是将其更改为:

select new { x }
而是返回
PartJoinTable
实体本身

select x
var cpaclassids=FetchProductTypes(id);
var cpaclids=string.Join(“,”,cpaclassids);
var query=(从partJoinTableRepository.GetPartJoinQuery()中的x连接到partRepository.GetPartsQuery()中的y
在x.PartId=z.PartId的partProductTypeReposiotry.GetPartProductTypesQuery()中加入z,其中y.IsSkiped==0&&&(y.IsDisabled!=“y”| | y.IsDisabled==null)&&z.CreatedDate==x.CreatedDate&&x.CreatedDate==Convert.ToDateTime(fromDate)选择x.Cast();
var predicate1=PredicateBuilder.True(查询);
predicate1=predicate1.And(x=>cpaclassids.Contains(x.ProductTypeId.ToString());
int lst=query.Where(谓词1).Select(x=>x.PartId).Distinct().ToList().Count();
正在返回一个匿名类型,其
x
属性类型为
PartJoinTable
。正如预期的那样,该匿名类型无法转换为
PartJoinTable

解决方案是将其更改为:

select new { x }
而是返回
PartJoinTable
实体本身

select x
var cpaclassids=FetchProductTypes(id);
var cpaclids=string.Join(“,”,cpaclassids);
var query=(从partJoinTableRepository.GetPartJoinQuery()中的x连接到partRepository.GetPartsQuery()中的y
在x.PartId=z.PartId的partProductTypeReposiotry.GetPartProductTypesQuery()中加入z,其中y.IsSkiped==0&&&(y.IsDisabled!=“y”| | y.IsDisabled==null)&&z.CreatedDate==x.CreatedDate&&x.CreatedDate==Convert.ToDateTime(fromDate)选择x.Cast();
var predicate1=PredicateBuilder.True(查询);
predicate1=predicate1.And(x=>cpaclassids.Contains(x.ProductTypeId.ToString());
int lst=query.Where(谓词1).Select(x=>x.PartId).Distinct().ToList().Count();

哪一行引发此异常?int lst=query.Where(谓词1)。选择(x=>x.PartId)。Distinct().ToList().Count();此行正在引发exceptionpublic IQueryable GetPartJoinQuery(){return Set;}哪一行正在引发此异常?int lst=query.Where(predicate1).Select(x=>x.PartId).Distinct().ToList().Count();此行正在抛出exceptionpublic IQueryable GetPartJoinQuery(){return Set;}