❔ SQL Table to Object
I have a SQL Table "Card" with a column "CardNr" and a column "CardType". How would I make this in to an object of my Card class?
4 Replies
Depends what you want to use
ADO? You'll need to wrestle with the reader, convert the values, all sorts of songs and dances
Dapper? Just execute the query and pass the class as a generic parameter
EF Core? Hopefully you're using code-first design, but if not... well I never used database-first design, but I guess you could just scaffold the code and use regular EF queries
If you're using Visual Studio, there's an EF Core extension for database-first
EF Core power tools
I've seen it recommended a lot
There's also a class called
DataTable
in C#. You can check it out as well
https://learn.microsoft.com/en-us/dotnet/api/system.data.datatable?view=net-8.0Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.