Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you generate classes in C# from a SQL Server Schema?

Tags:

c#

sql

automation

I have a sql database and I want to create a class for each table. I think a tool exists that allows me to extract information from a sql database and transform it into classes like "DataTable" or "DataRow". Afterwards, I could use those object in dataset.

like image 832
oL. Avatar asked Jan 02 '26 06:01

oL.


2 Answers

Instead of Data Table and Data sets you can use your own objects to represent data in your applications and to do so you can use some persistence frameworks and OR mappers (object relational mappers).For example you can use "Linq to Sql","Microsoft Entity framework" or NHibernate.

There are some code generation tools that let you generate code for these frameworks.

MyGeneration and CodeSmith as two of them that I know.

like image 88
Beatles1692 Avatar answered Jan 03 '26 20:01

Beatles1692


Maybe T4 (Text Template Transformation Toolkit) ist your friend...

like image 38
Oliver Avatar answered Jan 03 '26 18:01

Oliver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!