LINQ Not In,以便我可以在Merge中使用

时间:2011-09-13 14:18:28

标签: c# .net ado.net

我有这个,一个数据表和一个实体类,我可以转换为数据表。

UC010_WizardStepBusinessParkDataSet dataSet = new UC010_WizardStepBusinessParkDataSet();
        View_BuildingModule_UC010_BusinessPark_Wizard_GetBusinessParkData vwBusPark = new View_BuildingModule_UC010_BusinessPark_Wizard_GetBusinessParkData();

我想使用LINQ查询返回vwBusPark中不在dataset.BusinessPark中的那些查询。

我正在尝试类似下面的内容,但我被困住了:

   var query = dataSet.BusinessPark.Where(entry => !vwBusPark.toDataTable().AsEnumerable().Contains(entry.BusinessParkID));

它说:

错误1无法从用法推断出方法'System.Linq.Enumerable.Contains(System.Collections.Generic.IEnumerable,TSource)'的类型参数。尝试显式指定类型参数。 C:\ BITProjects \ TeamSystem \ luival \ refm \ DEV \ BuildingModule \ Business \ UC010_BusinessPark_Wizard \ BusinessParkWizardBL.cs 42 62 Ceusters.REFM.BuildingModule.Business

1 个答案:

答案 0 :(得分:2)

尝试

var vwBusParkIDs = vwBusPark.toDataTable().AsEnumerable().Select(r => Convert.ToInt32( r["BusinessParkId"]));
var query = dataSet.BusinessPark.Where(entry => !vwBusParkIDs.Contains(entry.BusinessParkID));