gpt4 book ai didi

c# - 无法创建常量值。只有原始类型

转载 作者:可可西里 更新时间:2023-11-01 08:58:20 26 4
gpt4 key购买 nike

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-to-entities 中,您不能将 Contains 与类一起使用,您只能将它与基本类型一起使用,因此您需要更改此设置:

where t.ttCategories.Contains(c)

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

关于c# - 无法创建常量值。只有原始类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14525182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com