c# – 无法创建一个常量值.只有原始类型
发布时间:2020-12-15 07:39:17 所属栏目:百科 来源:网络整理
导读: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 val
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(); } } 我究竟做错了什么? 解决方法
在linq到实体中,你不能使用包含一个类,你只能使用它与一个基本类型,所以你需要改变这一点:
where t.ttCategories.Contains(c) 至 where t.ttCategories.Any(x => x.UniqueProperty == c.UniqueProperty) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |