根据MySQL表创建C#类

use*_*041 10 .net c# mysql database persistence

是否有任何内置于.Net或visual studio中的内容可以让我根据MySql表创建类.我想我在谈论持久性.我只想让类成为表的1​​对1映射.有什么免费的吗?

Mee*_*orm 20

也许你需要这样的东西:

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 '}';
Run Code Online (Sandbox Code Playgroud)

  • 尼斯; 需要一个快速的方法来做到这一点,在紧要关头.创建了一个带有一些小改动的要点.https://gist.github.com/pdwetz/5368441 (4认同)