在LINQ中获取匿名类型错误

时间:2012-03-05 07:36:16

标签: c# linq anonymous-types

我有以下查询(只是一个例子),

List<int> batchId = entity.Select(x => x.Id).Distinct().ToList();
List<int> optionId = entity.Select(x => x.OptionId).Distinct().ToList();
List<int> prodId = entity.Select(x => x.ProductOption.ProductId).Distinct().ToList();
var itemsCount = (from source in entity
                  from option in optionId
                  from prod in prodId
                  where source.ProductOption.ProductId == prod
                  where source.Id == id
                  where source.OptionId == option
                  select new { 
                      a = source.abc.Id,
                      b = source.Option.Name,
                      d = prod
                   });

我每次都会收到匿名类型错误:

<MethodName>b__38(<>f__AnonymousTypef`2 <>

我该怎么办?

1 个答案:

答案 0 :(得分:0)

我认为你会在你的实体框架查询(三个第一行之一)中得到这个。因此,我建议检查你的实体模型,找出它有什么问题。

我的猜测:

   ist<int> prodId = entity.Select(x => x.ProductOption.ProductId).Distinct().ToList();

“Entity - &gt; ProductOption”关系

可能有问题