- 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)