Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create C# classes based of MySQL table

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 to be a 1 to 1 mapping of the table. Does anything free exist?

like image 463
user489041 Avatar asked Oct 14 '11 17:10

user489041


People also ask

What is create () in C?

1. Create: Used to Create a new empty file. Syntax in C language: int create(char *filename, mode_t mode) Parameter: filename : name of the file which you want to create.


1 Answers

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!

like image 86
Arthur Accioly Avatar answered Oct 20 '22 11:10

Arthur Accioly