c# – 无法创建一个常量值.只有原始类型

c# – 无法创建一个常量值.只有原始类型,第1张

概述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) /
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)
总结

以上是内存溢出为你收集整理的c# – 无法创建一个常量值.只有原始类型全部内容,希望文章能够帮你解决c# – 无法创建一个常量值.只有原始类型所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1256170.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存