无法创建恒定值。只有原始类型 [英] Unable to create a constant value. Only primitive types

查看:123
本文介绍了无法创建恒定值。只有原始类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?

推荐答案

在LINQ到实体,你不能使用类包含,你只能用原始类型使用它,所以你需要改变这一点:

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)

 where t.ttCategories.Any(x => x.UniqueProperty == c.UniqueProperty)

这篇关于无法创建恒定值。只有原始类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆