原本是想偷懒写一个存储过程,来生成实体类
CREATE DEFINER=`root`@`%` PROCEDURE `CreateModel`(IN `TableName` varchar(50),In `TableDescription` varchar(50))
BEGIN
Set
@hh = CHAR(10 using utf8),
@tab = char(9 using utf8),
@t2=(select GROUP_CONCAT(CONCAT(
@tab,@tab,'/// <summary>',@hh,
@tab,@tab,'/// ',Column_Comment,@hh,
@tab,@tab,'/// </summary>',@hh,
(case Column_Key when 'PRI' then CONCAT(@tab,@tab,'[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]',@hh) else '' end),
@tab,@tab,'public ',
case
when column_type like 'int%' then 'int'
when column_type like '%char%' then 'string'
when column_type like '%bit%' then 'bool'
when column_type like '%text%' then 'string'
when column_type like '%date%' then 'DateTime'
when column_type like '%tinyint%' then 'byte'
when column_type like '%decimal%' then 'decimal'
else column_type end,
' ',Column_Name,' ',' { get; set; } ',@hh,@hh) SEPARATOR ' ') from information_schema.columns
where table_schema = 'db'
and table_name = TableName);
SET @t1 = CONCAT('using System;',@hh,
'using SqlSugar;',
@hh,@hh,
'namespace APIHost.Domain.Entity',@hh,
'{',
@hh,@tab,'#region',' ',TableDescription,
@hh,@tab,'/// <summary>',
@hh,@tab,'/// ',TableDescription,
@hh,@tab,'/// </summary>',
@hh,@tab,'[SugarTable("',TableName,'", TableDescription = "',TableDescription,'")]',
@hh,@tab,'public class ',TableName,-- ' : dbbase',
@hh,@tab,'{',@hh,
@t2,
@hh,@tab,'}',
@hh,@tab,'#endregion',
@hh,'}');
Select @t1;
END
于是找了一个简单的表,写好存储过程,一切正常,一路复制粘贴几十个文件。
最后生成一下,结果一堆错,发现好多类都不全,无语了。
搞了半天才发现GROUP_CONCAT的数据缺半截。
必须设置下它的长度,再执行,就正常了。又要重新复制粘贴,为毛要用mysql。。。烦
SET SESSION group_concat_max_len = 10240;
show VARIABLES like 'group_concat_max_len'