今天在做开发时,需要把表映射成实体,又没有EF这种工具,就从网上下了一个工具,但使用时觉得太重了,所以就自己写了一个,基于mysql的。
功能:输入表名,得到这个表的poco实体
SELECT COLUMN_TYPE, CONCAT( ‘public ‘, CASE WHEN LEFT (COLUMN_TYPE, 3) = ‘int‘ THEN ‘int‘ WHEN LEFT (COLUMN_TYPE, 7) = ‘tinyint‘ THEN ‘byte‘ WHEN LEFT (COLUMN_TYPE, 8) = ‘smallint‘ THEN ‘short‘ WHEN LEFT (COLUMN_TYPE, 6) = ‘bigint‘ THEN ‘long‘ WHEN LEFT (COLUMN_TYPE, 5) = ‘float‘ THEN ‘float‘ WHEN LEFT (COLUMN_TYPE, 5) = ‘double‘ THEN ‘double‘ WHEN LEFT (COLUMN_TYPE, 5) = ‘decimal‘ THEN ‘decimal‘ WHEN LEFT (COLUMN_TYPE, 7) = ‘char‘ THEN ‘string‘ WHEN LEFT (COLUMN_TYPE, 7) = ‘varchar‘ THEN ‘string‘ WHEN LEFT (COLUMN_TYPE, 4) = ‘text‘ THEN ‘string‘ WHEN LEFT (COLUMN_TYPE, 8) = ‘datetime‘ THEN ‘DateTime‘ ELSE COLUMN_TYPE END, ‘ ‘, COLUMN_NAME, ‘{get;set;}‘ ) FROM information_schema. COLUMNS WHERE table_name = ‘system_companyfinancetaxsetting‘ AND table_schema = ‘pilipadb‘;
产生的结果
我们可以直接把第二列复制到VS的实体里就可以了,还是挺方便的!