We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
实体注册时,有些实体配置或者实体属性配置的需求比较统一,例如:
IEntityBatchConfiguration
/// <summary> /// 定义实体的批量配置功能 /// </summary> [MultipleDependency] public interface IEntityBatchConfiguration { /// <summary> /// 配置指定的<see cref="IMutableEntityType"/> /// </summary> /// <param name="modelBuilder">模型构建器</param> /// <param name="mutableEntityType">实体的<see cref="IMutableEntityType"/>类型</param> void Configure(ModelBuilder modelBuilder, IMutableEntityType mutableEntityType); }
TableNamePrefixConfiguration
/// <summary> /// 表名前缀配置 /// </summary> public class TableNamePrefixConfiguration : IEntityBatchConfiguration { /// <summary> /// 配置指定的<see cref="IMutableEntityType"/> /// </summary> /// <param name="modelBuilder">模型构建器</param> /// <param name="mutableEntityType">实体的<see cref="IMutableEntityType"/>类型</param> public void Configure(ModelBuilder modelBuilder, IMutableEntityType mutableEntityType) { string prefix = GetTableNamePrefix(mutableEntityType.ClrType); if (prefix.IsNullOrEmpty()) { return; } string tableName = $"{prefix}_{mutableEntityType.GetTableName()}"; modelBuilder.Entity(mutableEntityType.ClrType).ToTable(tableName); } /// <summary> /// 从实体类型获取表名前缀 /// </summary> /// <param name="entityType">实体类型</param> /// <returns></returns> protected virtual string GetTableNamePrefix(Type entityType) { TableNamePrefixAttribute attribute = entityType.GetAttribute<TableNamePrefixAttribute>(); return attribute?.Prefix; } }
services.AddSingleton<IEntityBatchConfiguration, TableNamePrefixConfiguration>();
The text was updated successfully, but these errors were encountered:
feat(efcore): 定义新接口IEntityBatchConfiguration,用于接管实体注册时的批量配置 #212
c2358e8
feat(efcore): 基于 #212 的改进,对实体时间属性UTC持久化功能进行重构 #159
72ff149
feat(efcore): 生成数据库时将属性[DisplayName]特性的值添加到表字段的描述信息中 #213 #212
c0cd399
No branches or pull requests
您的功能请求与现有问题有关吗?请描述
实体注册时,有些实体配置或者实体属性配置的需求比较统一,例如:
如果逐个写代码配置,很繁琐,需要统一配置
描述您想要的解决方案
定义新接口
IEntityBatchConfiguration
来接管这些配置实现示例:表前缀
TableNamePrefixConfiguration
应用
The text was updated successfully, but these errors were encountered: