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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With