LINQ over DataSets

Did you know you can LINQ over DataSets too? Well it’s pretty easy. So if you are doing something like this:

 foreach (DataRow row in dt.Rows)
{
  if (tempEvent.JobHandlerConfig.LicenseKey.Value.Equals(
                            int.Parse(row[0].ToString()))) 
  {
    valid = true;
    break;
  }
}

You can instead do this with LINQ:

 valid = dt.AsEnumerable().Where(p => p.Field<int>(0).
                   Equals(tempEvent.JobHandlerConfig.LicenseKey.Value)).Count() > 0;

Tip By: David McCarter

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s