Linq to SQL奇怪的错误

时间:2010-10-07 20:31:01

标签: linq-to-sql

我收到此错误:Could not format node 'Column' for execution as SQL

当我尝试制作任何匿名类型时:

 select new
 {
     NounTypeName = nt.Name,
     Attributes =
     (
         from a in nt.NounTypeAttributes
         group a by a.Attribute into g
         select new { 
             NounTypeId = nt.NounTypeId, 
             Key = g.Key + " (" + g.Count() + ")", 
             NounTypeAttributeId = 
                 (from i in g select i.NounTypeAttributeId)
                  .Take(1).SingleOrDefault(), Count = g.Count()
         }
     )
 });

当我在匿名类型中添加NounTypeId属性时会出现问题。

1 个答案:

答案 0 :(得分:1)

我可以建议将NounTypes和NounTypeAttributes加载到本地内存中,然后整形吗?

CustomDataContext myDC = new CustomDataContext();
DataLoadOptions myOptions = new DataLoadOptions();
myOptions.LoadWith<NounType>(nt => nt.NounTypeAttributes);
myDC.LoadOptions = myOptions;

List<NounType> theNounTypes =
(
  from nt in myDC.NounTypes
  where //TODO filterExpression
  select nt
).ToList();

var queryResult = from nt in theNounTypes
  select new
...
相关问题