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();
}
}
我做错了什么?
在 linq-to-entity 中,不能将 Include 与类一起使用,只能将其与基元类型一起使用,因此需要更改以下内容:
where t.ttCategories.Contains(c)
自
where t.ttCategories.Any(x => x.UniqueProperty == c.UniqueProperty)
var tags = (from t in db.ttproduktes
where t.ttCategories.Any(q => q.Id == c.Id)
select t.ttTags);