Skip to content

Select Into A Dictionary With LINQ

June 9, 2014
tags: , ,

This is neat, instead of doing it the long way, if you need to pull your data into a dictionary, you can do it like this:

 

Dictionary<string, int> facilityNpis = db.Facilities.Where(c => c.NPI.Trim().Length > 0).Select(a => new { a.NPI, a.ID }).AsEnumerable().ToDictionary(b => b.NPI, b => b.ID);

Advertisements
One Comment leave one →
  1. April 10, 2016 12:38 am

    Hey Ricky & Tracy.nAs a fellow ” waiting for what seems like the longest hardest time” parents.. I really can imagine how incredibly overwhelmed Click http://tu2s.in/searchll100830

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

%d bloggers like this: