score:3

Accepted answer

You can create a function that takes an IQueryable as a parameter.

The function would look like:

  private void CheckTable(IQueryable<EntityType> table)
  {
      var stage = (from s in table select s.ResourceId).ToList();
      foreach (var invalidResourceID in stage.Except(res).ToList())
      {
          errList.Add("Bad ID found:" + invalidResourceID);
      }
  }

  // Execute the function like:
  CheckTable(dc.TableOne);

You can choose if you make errList and res class level properties or if you pas them as parameters to the function

score:0

With some modification I was able to get this to work - I had to use the built in dynamic linq to select the property that I wanted.

private void CheckTable(System.Data.Objects.ObjectSet<EntityType> table)   
{
        var records = table.Select("BusinessEntityNbr").ToList();
        var values = (from r in records select (int?)r[0]).ToList();

        foreach (var invalidResourceID in values.Except(res).ToList())       
        {
           errList.Add("Bad ID found:" + invalidResourceID);       
        }
}

score:0

You may want to consider using entity SQL and DbDataRecord for unknown result types. See the Entity SQL samples in http://archive.msdn.microsoft.com/EFQuerySamples for some ideas on how to use Entity SQL.


Related Articles