当前位置: 首页 > news >正文

网页的制作与建设怀化网站优化多少钱

网页的制作与建设,怀化网站优化多少钱,驻马店标准网站建设,网站用什么字体后端采用Abp框架#xff0c;当前最新版本是7.4.0。 数据库使用MySQL#xff0c;在执行数据库迁移时#xff0c;写在Domain层的Entity类上的注释通通都没有#xff0c;这样查看数据库字段的含义时#xff0c;就需要对照代码来看#xff0c;有些不方便。今天专门来解决这个…后端采用Abp框架当前最新版本是7.4.0。 数据库使用MySQL在执行数据库迁移时写在Domain层的Entity类上的注释通通都没有这样查看数据库字段的含义时就需要对照代码来看有些不方便。今天专门来解决这个问题。 还是一顿搜索发现了两个方案 abp 框架拓展mysql 迁移增加数据库表和列备注 EFcoreMySql 数据迁移的时候怎么给表结构加注释   上述两篇文章 第一篇重载 MySqlMigrationsSqlGenerator 来实现加注释但是字段注释是通过Description属性来获取的这样字段上就要注释和Description重复写两遍。 第二篇直接通过工具读取xml文档生成 HasComment相关代码每次都需要手动修改DbContext代码。 都不是特别完美所以结合一下看看。具体方案还是重载MySqlMigrationsSqlGenerator但是通过读取xml来获取信息。 首先是SqlGenerator /// summary /// 拓展迁移操作增加数据表和列备注 /// /summary public class MyMigrationsSqlGenerator : MySqlMigrationsSqlGenerator {public MyMigrationsSqlGenerator(MigrationsSqlGeneratorDependencies dependencies,IMigrationsAnnotationProvider migrationsAnnotations,ICommandBatchPreparer commandBatchPreparer,IMySqlOptions mySqlOptions): base(dependencies, commandBatchPreparer, mySqlOptions){}protected override void Generate(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder){base.Generate(operation, model, builder);if (operation is CreateTableOperation || operation is AlterTableOperation)CreateTableComment(operation, model, builder);if (operation is AddColumnOperation || operation is AlterColumnOperation)CreateColumnComment(operation, model, builder);}/// summary/// 创建表注释/// /summary/// param nameoperation/param/// param namebuilder/paramprivate void CreateTableComment(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder){string tableName string.Empty;string description string.Empty;if (operation is AlterTableOperation){var t operation as AlterColumnOperation;tableName (operation as AlterTableOperation).Name;}if (operation is CreateTableOperation){var t operation as CreateTableOperation;var addColumnsOperation t.Columns;tableName t.Name;foreach (var item in addColumnsOperation){CreateColumnComment(item, model, builder);}}//description DbDescriptionHelper.GetDescription(tableName.Replace(jingdianConsts.DbTablePrefix, ));description GetDescription(tableName, null);if (tableName.IsNullOrWhiteSpace())throw new Exception(表名为空引起添加表注释异常.);var sqlHelper Dependencies.SqlGenerationHelper;builder.Append(ALTER TABLE ).Append(sqlHelper.DelimitIdentifier(tableName)).Append( COMMENT ).Append().Append(description).Append().AppendLine(sqlHelper.StatementTerminator).EndCommand();}/// summary/// 创建列注释/// /summary/// param nameoperation/param/// param namebuilder/paramprivate void CreateColumnComment(MigrationOperation operation, IModel model, MigrationCommandListBuilder builder){//alter table a1log modify column UUID VARCHAR(26) comment 修改后的字段注释;string tableName string.Empty;string columnName string.Empty;string columnType string.Empty;string description string.Empty;if (operation is AlterColumnOperation){var t (operation as AlterColumnOperation);columnType t.ColumnType;}if (operation is AddColumnOperation){var t (operation as AddColumnOperation);columnType t.ColumnType;description GetDescription(tableName, columnName);}if (columnName.IsNullOrWhiteSpace() || tableName.IsNullOrWhiteSpace() || columnType.IsNullOrWhiteSpace())throw new Exception(列名为空或表名为空或列类型为空引起添加列注释异常. columnName / tableName / columnType);var sqlHelper Dependencies.SqlGenerationHelper;builder.Append(ALTER TABLE ).Append(sqlHelper.DelimitIdentifier(tableName)).Append( MODIFY COLUMN ).Append(columnName).Append( ).Append(columnType).Append( COMMENT ).Append().Append(description).Append().AppendLine(sqlHelper.StatementTerminator).EndCommand();}private string GetDescription(string tableName, string? columnName){var type TableCommentRegister.Types[tableName];if (type null){return string.Empty;}string xmlPath type.Module.Name.Replace(dll,xml);XmlDocument xml new XmlDocument();xml.Load(xmlPath);var classNode xml.SelectSingleNode(($//member[nameT:{type.FullName}]));if (classNode null){return string.Empty;}if (columnName null){return classNode.InnerText.Trim();}else{var propertyNode xml.SelectSingleNode(($//member[nameP:{type.FullName}.{columnName}]));if (propertyNode null){return string.Empty;}return propertyNode.InnerText.Trim();}} } 这里面有一个点生成Sql时只知道table name和column name一般情况下列名就是属性名可以不考虑但是表名和类名可能会有差异比如前后缀之类的。参考1中就是直接做替换我考虑还是做了一个静态字典对象把表名和类名做了一个映射具体如下 /// summary /// 数据表注册器 /// /summary public static class TableCommentRegister {public static Dictionarystring, Type Types { get; set; } new Dictionarystring, Type();/// summary/// 配置实体对应的数据表同时注册类型用于后续生成备注/// /summary/// typeparam nameT实体类型/typeparam/// param namebuilder/param/// param nametableName数据表名/parampublic static void ToTableWithCommentT(this EntityTypeBuilderT builder, string tableName) where T : class{builder.ToTable(tableName);Types.TryAdd(tableName, typeof(T));} } 然后在DbContext类中针对表的处理代码如下 builder.EntityCompany(b {string tableName Consts.DbTablePrefix Company;b.ToTableWithComment(tableName);b.ConfigureByConvention(); //auto configure for the base class props}); 就是把之前的 ToTable 改成 ToTableWithComment 就可以了。 最后需要修改DbSchemaMigrator类把SqlGenerator注册进去。这里我就简单粗暴的复制了一下DbContextFactory类。因为DbContextFactory代码注释则表明了其只是用于EF Core console commands在Abp的DbMigrator程序中不起作用。 DbSchemaMigrator类中Abp 脚手架代码应该是这样的 public async Task MigrateAsync() {/* We intentionally resolving the XiuYuanDbContext* from IServiceProvider (instead of directly injecting it)* to properly get the connection string of the current tenant in the* current scope.*/await _serviceProvider.GetRequiredServiceXiuYuanDbContext().Database.MigrateAsync(); } 修改如下 public async Task MigrateAsync() { await CreateDbContext() .Database.MigrateAsync(); }public xxxDbContext CreateDbContext() {xxxEfCoreEntityExtensionMappings.Configure();var configuration BuildConfiguration();var connection configuration.GetConnectionString(xxxConsts.DbSchema);var builder new DbContextOptionsBuilderxxxDbContext().UseMySql(connection, ServerVersion.AutoDetect(connection), o o.SchemaBehavior(MySqlSchemaBehavior.Ignore))// 注意这里的ReplaceService.ReplaceServiceIMigrationsSqlGenerator, MyMigrationsSqlGenerator();return new xxxDbContext(builder.Options); }private static IConfigurationRoot BuildConfiguration() {var builder new ConfigurationBuilder().AddJsonFile(appsettings.json, optional: false);return builder.Build(); } 至此所有基础性工作都完成了后面再添加领域模型时记得把ToTable改成ToTableWithComment即可。
http://www.w-s-a.com/news/138553/

相关文章:

  • 校园网站建设管理工作制度大网站开发费用
  • 做logo赚钱的网站分类网站 模板
  • 网站建设完成报告织梦网站怎么做备份
  • 邯郸市城乡建设管理局网站vimwiki wordpress
  • 如何修改wordpress站名如何制作公司网站
  • 宁波网站建设与推广方案网站有了备案号之后能做什么
  • 汕头手机端建站模板pinterest app下载
  • 网站主机免费宁波网站建设优化诊断
  • 吧网站做软件的软件下载简单的ui界面制作
  • 陕西网站制作公司网页制作与设计代码
  • 做网站行情郑州微信网站开发
  • 河间网站建设制作null wordpress theme
  • h5网站制作网站开发网站建设文翻译工作
  • 网站建设 税种秦皇岛哪有网站优化公司
  • 专业开发网站设计找人做网页需要多少钱
  • 手机购物网站 建站网站建设网站制作网站设计
  • 基于iview的网站开发模板小程序制作需要什么语言
  • 精美网站设计保定建行网站首页登录
  • 网站建设常见问题做网站保存什么格式最好
  • 营销型网站建设与网页设计网站建设 amp 找VX cp5173
  • 新网站该如何做网站优化呢儿童手工
  • 湖北现代城市建设集团网站搜索引擎优化的作用
  • 上海做网站吧开一家软件开发公司需要什么
  • 阿里巴巴网站建设改图片建设厅官方网站河南
  • 邓砚谷电子商务网站建设镇江网
  • 网站空间支持什么程序工作服款式
  • 网站单页品牌网站建设 蝌蚪5小
  • 怎么做外贸网站需注意哪些做电脑系统的网站
  • 网站建设介绍推广用语河南网站优化外包服务
  • 课程网站模板贵州省城乡与建设厅网站