Geeks With Blogs
Path Notes of a Kodefu Master blog

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.

Posted on Tuesday, November 18, 2008 3:32 PM Kodefu | Back to top

Comments on this post: Generating Enums

# 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

Your comment:
 (will show your gravatar)

Copyright © Chris Eargle | Powered by: