Tôi có điều này LINQ truy vấn:Tại sao LINQ không kết hợp câu lệnh này?
// 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();
Đó là tạo ra lỗi này:
Unable to create a constant value of type 'System.Collections.Generic.IEnumerable`1'.
Only primitive types ('such as Int32, String, and Guid') are supported in this context.
[EDIT] Dưới đây là đoạn code của WeightedItem
:
public class WeightedItem
{
public int _id;
public decimal? _score;
public WeightedItem(int id, decimal? score)
{
_id = id;
_score = score;
}
}
Bạn có thể nhìn thấy những gì tôi đã làm sai? Mã biên dịch hoàn hảo và cả _ctx.Items và itemScores chứa các giá trị thích hợp.
Bạn có thể đăng mã cho WeightedItem – Lazarus
Rõ ràng WeightedItem không phải là một kiểu nguyên thủy. – DOK
Lazarus, xong rồi. DOK, có nghĩa là gì? – Mickel