Entity framework is a great ORM provided by Microsoft. There are a ton of examples of how to get up and running with it really quickly. The only problem with all of them, is the get you off on the wrong foot.
In all of the EF example guides, the DbContext class is typically deeply embedded into the core of your code. This of course is great for Entity framework because the effort to change will be next to impossible – speaking from experience of course here.
Instead, by making some subtle changes we can integrate Entity framework in a separate layer in case at some later date you wish to replace it. Of course, you might never need to replace it, but following these simple techniques will allow better segregation of code and even provide simpler unit testing.
If you use a framework of some sort, you probably haven’t thought about SQL injection for some time – in fact it almost seems dated to even discuss it. However, security should never be overlooked and it’s important to not trust third party applications and people by default! So what is the best way to prevent SQL injection?