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 に答える