dbEntities db = new dbEntities();
foreach (ttCategory c in db.ttCategories)
{
var tags=(from t in db.ttproduktes where t.ttCategories.Contains(c) select t.ttTags);
foreach (ttTag t in tags) // here it says:
// Unable to create a constant value - only primitive types
{
t.ToString();
}
}
我做错了什么?
答案 0 :(得分:19)
在linq-to-entities中,你不能将Contains与类一起使用,你只能使用它与原始类型,所以你需要改变它:
where t.ttCategories.Contains(c)
到
where t.ttCategories.Any(x => x.UniqueProperty == c.UniqueProperty)
答案 1 :(得分:1)
var tags = (from t in db.ttproduktes
where t.ttCategories.Any(q => q.Id == c.Id)
select t.ttTags);