我正在尝试返回项目列表 (vwProposedMigrations),其中 vwProposedMigrations 的 DeptCode IN 用户有权管理的部门列表。
result 包含 departmentCode 字符串列表。这些已通过早期的 entityQuery 加载并正确返回。
var result = (from r in wtps.Schedule_Owner_DeptCode_Mappings select r.DeptCode).ToList();
var data = wtps.GetVwProposedMigrationsQuery().Where(x=>result.Contains(x.DepartmentCode));
LoadOperation dataLoad = wtps.Load<vwProposedMigration>(data);
dataLoad.Completed += new EventHandler(LoadvwProposedMigrationsOperation_Completed);
但收到此错误:
Value of type 'System.Collections.Generic.List
1[System.String]' cannot be serialized as part of the query. 'System.Collections.Generic.List
1[System.String]' is not a supported type.
我试过使用 ObservableCollection
和 string[]
来保存部门代码列表,但同样的问题发生了。我见过很多使用 Contains 的示例,但这些示例会在数据加载后对数据进行操作,而不是限制初始查询。
我试图避免为 vwProposedMigrations 加载整个结果集,因为它大约有 38,000 行,所以我的目标是将查询限制为仅查询用户感兴趣的那些行。
谢谢 米克
最佳答案
请检查这个
var data = wtps.GetVwProposedMIgrationsQuery().Where(x=>result.Any(z=>z.DepartmentCode == x.DepartmentCode))
关于c# - 在 Silverlight 的 Entity Framework 中将 Contains as 'IN' 条款与 LINQ 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16687070/