Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生成数据库时将属性[DisplayName]特性的值添加到表字段的描述信息中 #213

Closed
gmf520 opened this issue Mar 17, 2021 · 0 comments
Labels
Feature 🔨 新功能,新特性 Finished ✔️ 实现并完工
Milestone

Comments

@gmf520
Copy link
Member

gmf520 commented Mar 17, 2021

您的功能请求与现有问题有关吗?请描述

生成数据库时将属性[DisplayName]特性的值添加到表字段的描述信息中

描述您想要的解决方案

实现

基于 #212 的实现,添加一个批量配置实现,使用HasComment配置实现此需求

    /// <summary>
    /// 给实体属性添加Comment配置
    /// 生成数据库时将属性[DisplayName]特性的值添加到表字段的描述信息中
    /// </summary>
    public class PropertyCommentConfiguration : IEntityBatchConfiguration
    {
        /// <summary>
        /// 配置指定的<see cref="IMutableEntityType"/>
        /// </summary>
        /// <param name="modelBuilder">模型构建器</param>
        /// <param name="mutableEntityType">实体的<see cref="IMutableEntityType"/>类型</param>
        public void Configure(ModelBuilder modelBuilder, IMutableEntityType mutableEntityType)
        {
            IMutableProperty[] mutableProperties = mutableEntityType.GetProperties().ToArray();
            foreach (IMutableProperty mutableProperty in mutableProperties)
            {
                if (mutableProperty.PropertyInfo == null)
                {
                    continue;
                }

                string display = mutableProperty.PropertyInfo.GetDescription();
                modelBuilder.Entity(mutableEntityType.ClrType).Property(mutableProperty.PropertyInfo.Name).HasComment(display);
            }
        }
    }

加入DI启用此功能

services.AddSingleton<IEntityBatchConfiguration, PropertyCommentConfiguration>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature 🔨 新功能,新特性 Finished ✔️ 实现并完工
Projects
None yet
Development

No branches or pull requests

1 participant