简体   繁体   中英

Built in code generation in vs.net 2008? or free via MS?

What code generation tools are built-in to vs.net 2008 or are officially available via Microsoft?

I know of:

  • Entity Framework
  • sqlmetal

What else is there?

Ideally i'm looking for something that will generate from an existing database schema.

If are looking specifically for a database/ORM generator you might be interested in looking at either llblgen or subsonic . Neither product is directly from Microsoft. Good luck with your search.

I have recently discovered T4 which is built in to VS2008

Assuming VB.Net (although works with c# just as well)

Create a file called template.tt and put the following in it....

<#@ template language="VB" debug="True" hostspecific="True" #>
<#@ output extension=".vb" debug="True" hostspecific="True" #>
Imports System
<# For Each Table as String in GetMyTables() #>
    Public Class <#=TableName#>
        Public Sub New
        End Sub 
    End Class
<#Next#>
<#+
Public Function GetMyTables() as String()
    Return new String(){"Table1", "Table2"}
End Function
#>

Ensure (if using vb) that show all files is true....and save the file.

You should see that a new file 'Template.vb' has been created with 1 class for each of 'Table1' and 'Table2'

You should be able to see how to customise this for almost any type of code generation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM