Example #1
0
        /// <summary>
        /// 初始化属性名
        /// 以添加mysql的EF列名映射
        /// </summary>
        /// <returns></returns>
        public async Task <PagedResultDto <PropertyInfoListDto> > InitColumnFullName( )
        {
            var query      = _entityRepository.GetAll();
            var entityList = await query
                             .ToListAsync();

            // TODO:根据传入的参数添加过滤条件
            foreach (var item in entityList)
            {
                var _entity = _entityRepository.FirstOrDefault(t => t.Id == item.Id);
                if (!string.IsNullOrWhiteSpace(_entity.PropertyFullName))
                {
                    _entity.PropertyName           = NamingConventions.GetPropertyName(_entity.PropertyFullName);
                    _entity.ColumnName             = NamingConventions.GetSqlColumnRename(_entity.PropertyName);
                    _entity.PropertyNameWithColumn = NamingConventions.GetPropertyNameWithColumn(_entity.PropertyFullName,
                                                                                                 _entity.ColumnName, _entity.IsZeroModule ?? 0);
                }
                //CurrentUnitOfWork.SaveChanges();  放于for循环外
                //推荐的做法是,每1000条数据,重新生成一次EFCONTEXT,保存一次,这样即可以避免本地EFCONTEXT占用过多内存,
                // 又可减少收发数据包的失误率,同时,SQL SERVER的解析时间短也能增加响应【推荐SaveChangesAsync异步替代方法】
                //https://www.cnblogs.com/izhaofu/p/4748563.html
                _entityRepository.Update(_entity);
            }
            var count = await query.CountAsync();

            var entityListDtos = ObjectMapper.Map <List <PropertyInfoListDto> >(entityList);
            //当所做的更改被写入数据库时,异步保存可避免阻塞线程。 这有助于避免胖客户端应用程序的 UI 被冻结。
            //异步操作还可以增加 Web 应用程序的吞吐量,可以释放线程以在数据库操作完成前去处理其他请求。
            //有关详细信息,请参阅使用 C# 异步编程。https://docs.microsoft.com/zh-cn/ef/core/saving/async
            await CurrentUnitOfWork.SaveChangesAsync();

            return(new PagedResultDto <PropertyInfoListDto>(count, entityListDtos));
        }
Example #2
0
        /// <summary>
        /// 迁移名批量修改
        /// form    C#大驼峰属性名    to  mysql下划线列名
        /// </summary>
        /// <returns></returns>
        //public async Task<PagedResultDto<PropertyInfoListDto>> MigratorReName()

        public async Task <int> MigratorReName()
        {
            var  entityTableName = "";
            var  propertyName    = "";
            bool isPropertyRow;
            var  query      = _entityRepository.GetAll().OrderBy(x => x.Id);//.OrderByDescending(x=>x.Id);
            var  entityList = query.ToList();

            // TODO:根据传入的参数添加过滤条件
            foreach (var item in entityList)
            {
                var _entity = _entityRepository.FirstOrDefault(t => t.Id == item.Id);
                if (!string.IsNullOrWhiteSpace(_entity.ColumnFullName))
                {
                    (_entity.ColumnName, propertyName, entityTableName, isPropertyRow) = NamingConventions
                                                                                         .GetColumnFirstName(_entity.ColumnFullName, entityTableName ?? "");
                    var columnName = _entity.ColumnName;
                    if (isPropertyRow)
                    {
                        _entity.Scope = NamingConventions.BuilderColumnName(columnName, propertyName, entityTableName);
                    }
                    //暂用DomainName存放新迁移FluentAPI
                    //_entity.DomainName = NamingConventions.ReplaceMigrator(_entity.ColumnFullName, _entity.ColumnName);
                }
                _entityRepository.Update(_entity);
            }
            var count = await query.CountAsync();

            //var entityListDtos = ObjectMapper.Map<List<PropertyInfoListDto>>(entityList);
            await CurrentUnitOfWork.SaveChangesAsync();

            //return new PagedResultDto<PropertyInfoListDto>(count, entityListDtos);
            return(count);
        }
Example #3
0
        /// <summary>
        /// 迁移名批量修改
        /// form    C#大驼峰属性名    to  mysql下划线列名
        /// </summary>
        /// <returns></returns>
        public async Task <PagedResultDto <PropertyInfoListDto> > MigratorReName()
        {
            var query      = _entityRepository.GetAll();
            var entityList = await query
                             .ToListAsync();

            // TODO:根据传入的参数添加过滤条件
            foreach (var item in entityList)
            {
                var _entity = _entityRepository.FirstOrDefault(t => t.Id == item.Id);
                if (!string.IsNullOrWhiteSpace(_entity.ColumnFullName))
                {
                    _entity.ColumnName = NamingConventions.GetColumnFirstName(_entity.ColumnFullName);