How do you map SQL results to C# objects?
I like to use Dapper.
Dapper is a blazing fast ORM for .NET applications.
It easily handles:
- Simple mappings
- 1:1 (one-to-one) relationships
- 1:N (one-to-many) relationships
- N:M (many-to-many) relationships
Here's an example of how you can map a one-to-one relationship with Dapper.
Let's say the object we want to return from a SQL query contains a nested object.
For example, a line item and its related product.
You'll need to tell Dapper how to map the SQL query into your C# objects.
You can also provide a delegate to connect the two.
Learn more about SQL-to-object mapping with Dapper here: https://t.co/Kl1dkNrVwL
Do you still use Dapper?
I often use it together with EF Core.
---
Sign up for the .NET Weekly with 75K+ other engineers, and get a free Clean Architecture template: https://t.co/3tQy0n8wWm
SQL is one of the most popular database query languages in the world.
So I got complete SQL notes, which costs $49.
But for 24H, it's FREE 🚀
Just:
- Like and repost
- Comment 'sql'
- Follow me so I can DM