Create C# classes based of MySQL table

后端 未结 10 1079
感情败类
感情败类 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:40

    The first example is very good but some types are missing so I'm sharing adding missing types (set, float etc ..)

    select 'table_name' INTO @table; #table name
    select 'db_name' 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 'shorte_prodottoe_prodotto' ,'int?' union all
    select 'bigint' ,'int?' union all
    select 'float' ,'float' union all
    select 'smallint' ,'sbyte' union all
    select 'int' ,'int?' union all
    select 'double' ,'double?' union all
    select 'decimal' ,'double?' union all
    select 'date' ,'DateTime?' union all
    select 'boolean' ,'bool' union all
    select 'set' ,'string' union all
    select 'tinyint' ,'bool?'
    ) tps on c.data_type like tps.orign
    where table_schema=@schema and table_name=@table union
    select '}';
    

提交回复
热议问题