首页 > 数据库 >C# net PDMan/CHINER/元数建模 生成SqlSugar 代码生成器模板

C# net PDMan/CHINER/元数建模 生成SqlSugar 代码生成器模板

时间:2022-08-30 17:13:45浏览次数:61  
标签:代码生成 set C# CHINER entity field SugarColumn true public

C# net PDMan/CHINER/元数建模 生成SqlSugar 代码生成器模板

C# net PDMan CHINER 元数建模 生成 SqlSugar 代码生成器模板

 

在版本>=4.0.0版本中 增加分类 代码生成器 >> C# >> Dapper

自带有SqlSugar模板,但是有无法识别null的类型,此模板支持

using System;
using System.Collections.Generic;
using SqlSugar;

$blankline
{{
    var today=new Date();
    var fullYear=today.getFullYear();
    var month=today.getMonth() + 1;
    var days=today.getDate();
    var sqlSugartable='[SugarTable("{{=it.entity.defKey}}", TableDescription = "{{=it.func.join(it.entity.defName,it.entity.comment,';')}}")]';
}}
/*
 * @author : [email protected]
 * @date : {{=fullYear}}-{{=month}}-{{=days}}
 * @desc : {{=it.func.join(it.entity.defName,it.entity.comment,'-')}}
 */
namespace Model.DBModel
{
    /// <summary>
    /// {{=it.func.join(it.entity.defName,it.entity.comment,';')}}
    /// </summary>
    {{=sqlSugartable}}
    public class {{=it.entity.defKey}}
    {
        {{~it.entity.fields:field:index}}
        /// <summary>
        /// {{=it.func.join(field.defName,field.comment,';')}}
        /// </summary>
        {{? field.primaryKey }}
        [SugarColumn(IsPrimaryKey = true)]
        {{?}}        {{? !field.notNull }}
        [SugarColumn(IsNullable = true)]
        {{?}}
        public {{=field.type}}{{? field.type!='string'&&!field.notNull}}?{{?}} {{=field.defKey}}{ get; set; }$blankline
        {{~}}
    }
}

  

生成的效果为:

    /// <summary>
    /// 测试记录
    /// </summary>
    [SugarTable("PlayLog", TableDescription = "测试记录")]
    public class PlayLog
    {
        /// <summary>
        /// Id
        /// </summary>
        [SugarColumn(IsPrimaryKey = true)]
        public string Id { get; set; }
        /// <summary>
        /// 产品编号
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string ProductCode { get; set; }
        /// <summary>
        /// 测试人员
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string UserTest { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public DateTime? CreatedTime { get; set; }
        /// <summary>
        /// 更新时间
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public DateTime? UpdatedTime { get; set; }
    }

  

 

ok!

 

标签:代码生成,set,C#,CHINER,entity,field,SugarColumn,true,public
From: https://www.cnblogs.com/ping9719/p/16640062.html

相关文章