Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to create a constant value. Only primitive types

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

What am i doing wrong?

like image 297
daniel Avatar asked Jan 25 '13 15:01

daniel


2 Answers

In linq-to-entities, you can't use Contains with a class, you can only use it with a primitive type, so you need to change this:

where t.ttCategories.Contains(c)

to

 where t.ttCategories.Any(x => x.UniqueProperty == c.UniqueProperty)
like image 198
Aducci Avatar answered Sep 28 '22 00:09

Aducci


var tags = (from t in db.ttproduktes
            where t.ttCategories.Any(q => q.Id == c.Id)
            select t.ttTags);
like image 27
daryal Avatar answered Sep 28 '22 00:09

daryal