Unable to create a constant value. Only primitive types

后端 未结 2 1740
误落风尘
误落风尘 2021-02-08 11:35
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);
          


        
相关标签:
2条回答
  • 2021-02-08 11:58

    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)
    
    0 讨论(0)
  • 2021-02-08 11:59
    var tags = (from t in db.ttproduktes
                where t.ttCategories.Any(q => q.Id == c.Id)
                select t.ttTags);
    
    0 讨论(0)
提交回复
热议问题