Create C# classes based of MySQL table

后端 未结 10 1054
感情败类
感情败类 2021-02-02 00:44

Is there anything built into .Net or visual studio that will allow my to create classes based off of a MySql table. I guess I am talking about persistence. I just want the class

相关标签:
10条回答
  • 2021-02-02 01:18

    maybe you need something like this:

    select 'my_table' into @table; #table name
    select 'my_database' into @schema; #database name
    select concat('public class ',@table,'{') union
    select concat('public ',tps.dest,' ',column_name,'{get;set;}') from  information_schema.columns c
    join( #datatypes mapping
    select 'char' as orign ,'string' as dest union all
    select 'varchar' ,'string' union all
    select 'longtext' ,'string' union all
    select 'datetime' ,'DateTime?' union all
    select 'text' ,'string' union all
    select 'bit' ,'int?' union all
    select 'bigint' ,'int?' union all
    select 'int' ,'int?' union all
    select 'double' ,'double?' union all
    select 'decimal' ,'double?' union all
    select 'date' ,'DateTime?' union all
    select 'tinyint' ,'bool?'
    ) tps on c.data_type like tps.orign
    where table_schema=@schema and table_name=@table union
    select '}';
    
    0 讨论(0)
  • 2021-02-02 01:26

    I use NHibernate with MyGeneration

    MyGeneration is a program that can read your database schema and generate code based on a template (in the case of NHibernate, the Entities and Mappings)

    0 讨论(0)
  • 2021-02-02 01:34

    there appears to be a way to get EntityFramework working with MySQL

    Using MySQL with Entity Framework

    http://weblogs.asp.net/gunnarpeipman/archive/2010/12/09/getting-mysql-work-with-entity-framework-4-0.aspx

    0 讨论(0)
  • 2021-02-02 01:35

    You can use the Entity Framework for this. It connects well with MySQL. I've been following this tutorial: http://www.devart.com/dotconnect/mysql/articles/tutorial_ef.html

    0 讨论(0)
  • 2021-02-02 01:37

    Subsonic (open source) works with MySQL (5.0+) with special support for InnoDB -

    http://subsonicproject.com/

    0 讨论(0)
  • 2021-02-02 01:39

    I adjusted the sql of MeelStorm because it was appearing some errors regarding the language. I put other types of data as well and I drop the class declaration because this is unnecessary to me. So the final result is:

    select concat('public ',tps.dest,' ',column_name,'{get;set;}') as code 
    from  information_schema.columns c
    join(
    select 'char' as orign ,'string' as dest union all
    select 'varchar' ,'string' union all
    select 'longtext' ,'string' union all
    select 'datetime' ,'DateTime' union all
    select 'text' ,'string' union all
    select 'bit' ,'int' union all
    select 'bigint' ,'int' union all
    select 'int' ,'int' union all
    select 'double' ,'double' union all
    select 'decimal' ,'double' union all
    select 'date' ,'DateTime' union all
    select 'tinyint' ,'bool'
    ) tps on c.data_type like tps.orign
    where table_schema='your_schema' and table_name='your_table' 
    order by c.ordinal_position
    

    Hope it helps. Cheers!

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