How can I generate database tables from C# classes?

前端 未结 12 1441
谎友^
谎友^ 2020-12-02 05:26

Does anyone know a way to auto-generate database tables for a given class? I\'m not looking for an entire persistence layer - I already have a data access solution I\'m usi

相关标签:
12条回答
  • 2020-12-02 05:58

    I think for complex data types, you should extend them by specifying a ToDB() method which holds their own implementation for creating tables in the DB, and this way it becomes auto-recursive.

    0 讨论(0)
  • 2020-12-02 06:03

    Try DaoliteMappingTool for .net. It can help you generate the classes. Download form Here

    0 讨论(0)
  • 2020-12-02 06:09

    Subsonic is also another option. I often use it to generate entity classes that map to a database. It has a command line utility that lets you specify tables, types, and a host of other useful things

    0 讨论(0)
  • 2020-12-02 06:11

    I know you're looking for an entire persistence layer, but NHibernate's hbm2ddl task can do this almost as a one-liner.

    There is a NAnt task available to call it which may well be of interest.

    0 讨论(0)
  • 2020-12-02 06:12

    You can do the opposite, database table to C# classes here: http://pureobjects.com/dbCode.aspx

    0 讨论(0)
  • 2020-12-02 06:14

    Try out my CreateSchema extension method for objects at http://createschema.codeplex.com/

    It returns a string for any object containing CREATE TABLE scripts.

    0 讨论(0)
提交回复
热议问题