I’ve been spreading myself to thin lately by enrolling in to many courses at one time. Ethical Hacking and C# MVC are a bit much for me on top of my full-time Dev / Engineer role. I’m backing off the Hacking for a bit as it is very time consuming when you get in to lab testing.
So for now it is back to C# MVC, ORMs and Web Forms Apps for a while.
In this article I’ll be discussing my journey in improving my C# coding skills as I build a prototype application for managing a simple users table.
Resources for this article:
- YouTube Video: Tim Corey – How to connect C# to SQL (the easy way) using Dapper ORM
- Helpful Article: How to insert a new record in to my table if not exists SQL Server.
What is an ORM?
Object relational mapper (ORM) is a tool for converting data between two incompatible types system. In this case it is from a C# Model / Object and a SQL Stored Procedure.
In this case, we’ll be using the “Dapper” ORM library that Tim Corey references in his video tutorial. There are others like the “Entity Framework”. In the wild, I even ran in to one called MassiveORM that another developer used on an undocumented project that I picked up at a start-up. :-\
The most important thing to understand about ORMs is that C# models you build for your object need to closely mirror the table structure database. Again, ORMs facilitate the conversion of data between two system with different typing systems.
For example, SQL call to store data may need an bigint typed value and the C# is taking in form data in string format that needs be converted to an integer before the ORM can accept it for conversion to bigint in SQL. I hope that makes sense.
Building your Database Tables and C# Models so they work with the ORM
Getting your data in and out of your database using the ORM requires you to do some planning.