【发布时间】:2009-12-30 19:48:21
【问题描述】:
我有这个 LINQ 查询:
// types...
LinkedList<WeightedItem> itemScores = new LinkedList<WeightedItem>();
var result = from i in _ctx.Items
join s in itemScores on i.Id equals s._id
orderby s._score descending
select new ItemSearchResult(i, s._score);
// this fails:
return result.ToList();
产生此错误的原因:
无法创建类型为“System.Collections.Generic.IEnumerable`1”的常量值。
此上下文仅支持原始类型(“例如 Int32、String 和 Guid”)。
[编辑]这是WeightedItem的代码:
public class WeightedItem
{
public int _id;
public decimal? _score;
public WeightedItem(int id, decimal? score)
{
_id = id;
_score = score;
}
}
你能看出我做错了什么吗?代码编译完美,_ctx.Items 和 itemScores 都包含正确的值。
【问题讨论】:
-
能否贴出WeightedItem的代码
-
显然 WeightedItem 不是原始类型。
-
拉撒路,完成了。 DOK,什么意思?
标签: c# linq entity-framework join linq-to-entities