Пример #1
0
 /// <summary>
 /// 用于查找指定类型的仓库。
 /// </summary>
 /// <typeparam name="TRepository"></typeparam>
 /// <returns></returns>
 public static TRepository Concrete <TRepository>()
     where TRepository : EntityRepository
 {
     return(RF.Concrete <TRepository>());
 }
Пример #2
0
 /// <summary>
 /// 用于查找指定实体的仓库。
 /// </summary>
 /// <returns></returns>
 public static EntityRepository Find(Type entityType)
 {
     return(RF.Find(entityType));
 }
Пример #3
0
 /// <summary>
 /// 用于查找指定实体的仓库。
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <returns></returns>
 public static EntityRepository Find <TEntity>()
     where TEntity : Entity
 {
     return(RF.Find <TEntity>());
 }
Пример #4
0
        /// <summary>
        /// 重新设置整个表的所有 TreeIndex。
        /// 注意,此方法只保证生成的 TreeIndex 有正确的父子关系,同时顺序有可能被打乱。
        /// </summary>
        /// <param name="repository"></param>
        public static void ResetTreeIndex(EntityRepository repository)
        {
            using (var tran = RF.TransactionScope(repository))
            {
                //先清空
                var dp     = repository.RdbDataProvider;
                var table  = dp.DbTable;
                var column = table.Columns.First(c => (c as DbColumn).Property == Entity.TreeIndexProperty);
                using (var dba = dp.CreateDbAccesser())
                {
                    dba.ExecuteText(string.Format("UPDATE {0} SET {1} = NULL", table.Name, column.Name));
                }

                var all = repository.GetAll();
                if (all.Count > 0)
                {
                    //如果加载的过程中,第一个节点刚好是根节点,
                    //则加载完成后是一棵完整的树,Index 也生成完毕,不需要再次处理。
                    if (all.IsTreeRootList)
                    {
                        all.ResetTreeIndex();
                        repository.Save(all);
                    }
                    else
                    {
                        var cloneOptions = CloneOptions.ReadSingleEntity();
                        var oldList      = new List <Entity>();
                        all.EachNode(e =>
                        {
                            var cloned = repository.New();
                            cloned.Clone(e, cloneOptions);
                            cloned.PersistenceStatus = PersistenceStatus.Unchanged;

                            oldList.Add(cloned);
                            return(false);
                        });

                        var newList = repository.NewList();
                        while (oldList.Count > 0)
                        {
                            foreach (var item in oldList)
                            {
                                var treePId = item.TreePId;
                                if (treePId == null)
                                {
                                    newList.Add(item);
                                    oldList.Remove(item);
                                    break;
                                }
                                else
                                {
                                    var parent = newList.EachNode(e => e.Id.Equals(treePId));
                                    if (parent != null)
                                    {
                                        parent.TreeChildren.LoadAdd(item);
                                        oldList.Remove(item);
                                        break;
                                    }
                                }
                            }
                        }
                        TreeHelper.MarkTreeFullLoaded(newList);
                        newList.ResetTreeIndex();
                        repository.Save(newList);
                    }
                }

                tran.Complete();
            }
        }