0

I have this, one datatable and one entity class that I can convert to a datatable.

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

I want to return with a LINQ query the ones that are in vwBusPark that are not in dataset.BusinessPark.

I was trying something like the following but I am stuck:

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

It says:

Error 1 The type arguments for method 'System.Linq.Enumerable.Contains(System.Collections.Generic.IEnumerable, TSource)' cannot be inferred from the usage. Try specifying the type arguments explicitly. C:\BITProjects\TeamSystem\luival\refm\DEV\BuildingModule\Business\UC010_BusinessPark_Wizard\BusinessParkWizardBL.cs 42 62 Ceusters.REFM.BuildingModule.Business

Luis Valencia
  • 32,619
  • 93
  • 286
  • 506

1 Answers1

2

Try

var vwBusParkIDs = vwBusPark.toDataTable().AsEnumerable().Select(r => Convert.ToInt32( r["BusinessParkId"]));
var query = dataSet.BusinessPark.Where(entry => !vwBusParkIDs.Contains(entry.BusinessParkID));
Bala R
  • 107,317
  • 23
  • 199
  • 210
  • 3 exceptions: 'System.Data.DataRow' does not contain a definition for 'BusinessParkID' and no extension method 'BusinessParkID' accepting a first argument of type 'System.Data.DataRow' could be found – Luis Valencia Sep 13 '11 at 14:24
  • Error 2 Instance argument: cannot convert from 'System.Data.EnumerableRowCollection' to 'System.Collections.Generic.IEnumerable' – Luis Valencia Sep 13 '11 at 14:24
  • Error 3 'System.Data.EnumerableRowCollection' does not contain a definition for 'Contains' and the best extension method overload 'System.Linq.Enumerable.Contains(System.Collections.Generic.IEnumerable, TSource)' has some invalid arguments – Luis Valencia Sep 13 '11 at 14:24
  • 1
    @Luis See my edit. I've used Covert.ToInt32() for BusinessParkId but if that's not accurate, use the right conversion method and see if it helps. – Bala R Sep 13 '11 at 14:26
  • at least it compiled, now I need to be able to use the results of query, in the Merge method?? any idea? if (vwBusPark.Query.Load()) dataSet.BusinessPark.Merge(query???, true, System.Data.MissingSchemaAction.Ignore); – Luis Valencia Sep 13 '11 at 14:28
  • @Luis I'm not very familiar with DataTable.Merge() but it definitely does not take IEnumerable for a parameter. You can look into converting IEnumerable to DataTable http://stackoverflow.com/questions/1253725/convert-ienumerable-to-datatable and then maybe use the result to Merge. – Bala R Sep 13 '11 at 14:37