Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markup to c# & SQL?

I was wondering if there was a simple markup that would generate my C# classes for me along with (My)SQL create table. Preferably one that supports indexes and FK


2 Answers

You can create an entity model with the designer. Afterwards you can enable sql tracing/or export the creation script via your favorite database tool. Just look for "LINQ to SQL Classes" when adding a new file to the project. The file extension is dbml.

like image 137
Marco Klein Avatar answered Sep 04 '26 12:09

Marco Klein


We have used CodeSmith to do this for a long time. You can generate classes from existing SQL tables and the scripting capability of the tool allows you to fine tune the output to be exactly what you want. For example, all of our business classes inherit from the same base class, so we just modified the script to include this base class in the generated output.

like image 27
competent_tech Avatar answered Sep 04 '26 13:09

competent_tech



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!