EF + T4 自动生成类继承 BaseEntity

BaseEntity.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZSZ.Model
{
   public partial class BaseEntity
    {
        public long Id { get; set; }
        public bool IsDeleted { get; set; }
        public System.DateTime CreateDateTime { get; set; }
    }
}

 

Model1.tt

<#
        var simpleProperties = typeMapper.GetSimpleProperties(entity);
        if (simpleProperties.Any())
        {
            foreach (var edmProperty in simpleProperties)
            {
                //去除 BaseEntity 中的属性
                if (edmProperty.Name=="Id"||edmProperty.Name=="IsDeleted"||edmProperty.Name=="CreateDateTime") 
                {
                    continue;
                }
#>
    <#=                    codeStringGenerator.Property(edmProperty)#>
<#
            }
        }
#>

 

        public string EntityClassOpening(EntityType entity)
        {
            return string.Format(
                CultureInfo.InvariantCulture,
                "{0} {1}partial class {2}:BaseEntity",   //继承 BaseEntity
                Accessibility.ForType(entity),
                _code.SpaceAfter(_code.AbstractOption(entity)),
                _code.Escape(entity));
        }

 

posted @ 2018-07-06 22:23  linyongqin  阅读(741)  评论(0编辑  收藏  举报