[英]Using Contains as 'IN' cluase with LINQ in Entity Framework in Silverlight
我想返回的項目(vwProposedMigrations)的列表,其中vwProposedMigrations的是DEPTCODE IN科指南用戶被授權管理的列表。
結果包含一個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);
但收到此錯誤:
類型'System.Collections.Generic.List
1[System.String]' cannot be serialized as part of the query. 'System.Collections.Generic.List
1[System.String]' cannot be serialized as part of the query. 'System.Collections.Generic.List
1 [System.String]'不是受支持的類型。
我嘗試使用ObservableCollection
和string[]
來保存部門代碼列表,但是會發生相同的問題。 我已經看到了許多使用Contains的示例,但是這些示例在數據加載后就對數據進行操作,而不是限制初始查詢。
我試圖避免加載vwProposedMigrations的整個結果集,因為它大約有38,000行,所以我的目標是將查詢限制為僅用戶感興趣的那些行。
謝謝米克
檢查一下:
var result = (from r in wtps.Schedule_Owner_DeptCode_Mappings select r.DeptCode);
var data = wtps.GetVwProposedMigrationsQuery().Where(x=>result.Contains(x.DepartmentCode));
請檢查一下
var data = wtps.GetVwProposedMIgrationsQuery().Where(x=>result.Any(z=>z.DepartmentCode == x.DepartmentCode))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.