Generating Enums

In a recent post, Deepak describes how to generate enums using Linq to Sql and SqlMetal.

1. Generate dbml using SqlMetal.
2. Find reference columns in the dbml that will be used as enums in code. Change their type to the enum name.
3. Generate code using SqlMetal.

I find this pretty interesting, but there would need to be some kind of conventions or configuration to denote which tables will be used as enumerations in the code. I think the way to tackle this is to create a custom msbuild task that will replace the enums for you based on either an item group or an xml property. This whole thing could be wrapped up in msbuild and applied in a separate proj file or in the AfterBuild or BeforeBuild target of one of the projects.

Print | posted on Tuesday, November 18, 2008 3:32 PM

Comments on this post

# re: Generating Enums

Requesting Gravatar...
Happy to know that you found my approach interesting.

In my solution I have all my enums in a project. And in my custom process I iterate through all enums (using a bit of reflection to make sure they are enums). This is how I identify what I need to change in dbml. I agree with packaging this in msbuild using a custom task if you want to re-generate LINQ To SQL code as part of build process.
Left by Deepak on Nov 18, 2008 7:17 PM

# re: Generating Enums

Requesting Gravatar...
http://www.thecodejunkie.com/2008/11/generate-enums-from-database-using-text.html
Left by Busby SEO Test on Dec 18, 2008 10:01 AM

Your comment:

 (will show your gravatar)
 
Please add 4 and 1 and type the answer here: