10
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();
    }
}

我究竟做错了什么?

4

2 回答 2

19

在 linq-to-entities 中,不能将 Contains 与类一起使用,只能将其与原始类型一起使用,因此需要更改:

where t.ttCategories.Contains(c)

 where t.ttCategories.Any(x => x.UniqueProperty == c.UniqueProperty)
于 2013-01-25T15:52:24.547 回答
1
var tags = (from t in db.ttproduktes
            where t.ttCategories.Any(q => q.Id == c.Id)
            select t.ttTags);
于 2013-01-25T15:54:02.480 回答