Generic (and easy) Entity Framework Repository

There are plenty of examples of generic Entity Framework repositories out on the world wide web. So why post another? In my searches in the past for generic repo examples I came across a lot of code, a large number of it was old and not compatible with the latest versions of EF. Other examples out there didn’t seem ‘enterprisey’ and more for small apps (in that case I’d just use Massive or Dapper).

metadata-management-repositoryRecently I’ve been talking with people, about Azure and how to use it’s SQL Azure PaaS database, or following good IoC practices and how best to DI entity framework into business or service layer. This now gives me the opportunity to point to a GitHub repo and explain live code people can use.

Last night I pulled out the Repository from Resgrid and put it on Github as Apache 2.0 OSS. Resgrid is a SaaS product utilizing Microsoft Azure, providing logistics, management and communication tools to first responder organizations like volunteer fire departments, career fire departments, EMS, search and rescue, CERT, public safety, disaster relief organizations, etc. It was founded in late 2012 by myself and Jason Jarrett (staxmanade).

Resgrid currently runs:

2 Load Balanced Web Servers (For the public and private site)

2 Load Balanced Web Servers (For our API)

2 Backend (Worker Role) Instances

All of these components utilize this repo and EF to communicate to a single database. Because of the volume and interaction our repository has evolved greatly over the years and will continue to evolve. Resgrid currently sees thousands of hits a day, signs up around 3 departments every weekday and has thousands of app’s hitting our API. In addition to the workers that have jobs that run sometimes every 30 seconds.

Features of the current repository:

  1. Code First & EF6
  2. No code data access (create the POCO, added it to the data context and then just inject GenericRepository<T> into your services/BLL
  3. Synchronous and Async/Await data access calls
  4. Simple API for Updates and Saves
  5. Works with Integer and Guid based ID values

So go check the code out on our GitHub https://github.com/Resgrid/GenericEFRepo feel free to submit PR’s and issues there as well. We intend to keep it updated with the latest versions of EF, performance enhancements and usability as we go forward.

About: Shawn Jackson

I’ve spent the last 18 years in the world of Information Technology on both the IT and Development sides of the aisle. I’m currently a Software Engineer for Paylocity. In addition to working at Paylocity, I’m also the Founder of Resgrid, a cloud services company dedicated to providing logistics and management solutions to first responder organizations, volunteer and career fire departments, EMS, ambulance services, search and rescue, public safety, HAZMAT and others.