예제 #1
0
        /// <summary>
        /// To Attach entities. When updating data, only the changed part is updated. <br />
        /// 附加实体。在更新数据时,只更新变化的部分
        /// </summary>
        public TEntity Attach()
        {
            Repository ??= Orm.GetRepository <TEntity>();
            var item = this as TEntity;

            Repository.Attach(item);
            return(item);
        }
예제 #2
0
        /// <summary>
        /// To Attach entities. When updating data, only the changed part is updated. <br />
        /// 附加实体。在更新数据时,只更新变化的部分
        /// </summary>
        public TEntity Attach()
        {
            if (Repository == null)
            {
                Repository = Orm.GetRepository <TEntity>();
            }
            var item = this as TEntity;

            Repository.Attach(item);
            return(item);
        }
예제 #3
0
    /// <summary>
    /// 更新或插入
    /// </summary>
    /// <returns></returns>
    public virtual TEntity Save()
    {
        this.UpdateTime = DateTime.Now;
        if (this.Repository == null)
        {
            this.Repository = Orm.GetRepository <TEntity>();
        }

        this.Repository.UnitOfWork = UnitOfWork.Current.Value;
        return(this.Repository.InsertOrUpdate(this as TEntity));
    }
예제 #4
0
    /// <summary>
    /// 插入数据
    /// </summary>
    public virtual Task <TEntity> InsertAsync()
    {
        this.CreateTime = DateTime.Now;
        if (this.Repository == null)
        {
            this.Repository = Orm.GetRepository <TEntity>();
        }

        this.Repository.UnitOfWork = UnitOfWork.Current.Value;
        return(this.Repository.InsertAsync(this as TEntity));
    }
예제 #5
0
        /// <summary>
        /// 附加实体,在更新数据时,只更新变化的部分
        /// </summary>
        public TEntity Attach()
        {
            if (this.Repository == null)
            {
                this.Repository = Orm.GetRepository <TEntity>();
            }

            var item = this as TEntity;

            this.SetTenantId();
            this.Repository.Attach(item);
            return(item);
        }
예제 #6
0
파일: BaseEntity.cs 프로젝트: 2881099/ojbk
 /// <summary>
 /// 获取新的仓库对象
 /// </summary>
 /// <returns></returns>
 public static DefaultRepository <TEntity, TKey> GetRepository() => Orm.GetRepository <TEntity, TKey>();
예제 #7
0
        static void TrackToList(object list)
        {
            if (list == null)
            {
                return;
            }

            var ls = list as IList <TEntity>;

            if (ls == null)
            {
                var ie = list as IEnumerable;
                if (ie == null)
                {
                    return;
                }

                var isFirst = true;
                IBaseRepository <TEntity> baseRepo = null;

                foreach (var item in ie)
                {
                    if (item == null)
                    {
                        return;
                    }

                    if (isFirst)
                    {
                        isFirst = false;
                        var itemType = item.GetType();
                        if (itemType == typeof(object))
                        {
                            return;
                        }
                        if (itemType.FullName.Contains("FreeSqlLazyEntity__"))
                        {
                            itemType = itemType.BaseType;
                        }
                        if (Orm.CodeFirst.GetTableByEntity(itemType)?.Primarys.Any() != true)
                        {
                            return;
                        }
                        if (itemType.GetConstructor(Type.EmptyTypes) == null)
                        {
                            return;
                        }
                        if (item is BaseEntity <TEntity> == false)
                        {
                            return;
                        }
                    }

                    if (item is BaseEntity <TEntity> entity)
                    {
                        if (baseRepo == null)
                        {
                            baseRepo = Orm.GetRepository <TEntity>();
                        }
                        entity.Repository = baseRepo;
                        entity.Attach();
                    }
                }
                return;
            }

            if (ls.Any() == false)
            {
                return;
            }
            if (ls.FirstOrDefault() is BaseEntity <TEntity> == false)
            {
                return;
            }
            if (Orm.CodeFirst.GetTableByEntity(typeof(TEntity))?.Primarys.Any() != true)
            {
                return;
            }

            IBaseRepository <TEntity> repo = null;

            foreach (var item in ls)
            {
                if (item is BaseEntity <TEntity> entity)
                {
                    if (repo == null)
                    {
                        repo = Orm.GetRepository <TEntity>();
                    }
                    entity.Repository = repo;
                    entity.Attach();
                }
            }
        }
예제 #8
0
        static void TrackToList(object list)
        {
            if (list is null)
            {
                return;
            }

            if (list is not IList <TEntity> ls)
            {
                if (list is not IEnumerable ie)
                {
                    return;
                }

                var isFirst = true;
                IBaseRepository <TEntity> baseRepo = null;

                foreach (var item in ie)
                {
                    if (item is null)
                    {
                        return;
                    }

                    if (isFirst)
                    {
                        isFirst = false;
                        var itemType = item.GetType();
                        if (itemType == typeof(object))
                        {
                            return;
                        }
                        if (itemType.FullName !.Contains("FreeSqlLazyEntity__"))
                        {
                            itemType = itemType.BaseType;
                        }
                        if (Orm.CodeFirst.GetTableByEntity(itemType)?.Primarys.Any() != true)
                        {
                            return;
                        }
                        if (item is not BaseEntity <TEntity> )
                        {
                            return;
                        }
                    }

                    if (item is BaseEntity <TEntity> entity)
                    {
                        baseRepo ??= Orm.GetRepository <TEntity>();
                        entity.Repository = baseRepo;
                        entity.Attach();
                    }
                }

                return;
            }

            if (ls.Any() == false)
            {
                return;
            }

            if (ls.FirstOrDefault() is not BaseEntity <TEntity> )
            {
                return;
            }

            if (Orm.CodeFirst.GetTableByEntity(typeof(TEntity))?.Primarys.Any() != true)
            {
                return;
            }

            IBaseRepository <TEntity> repo = null;

            foreach (var item in ls)
            {
                if (item is BaseEntity <TEntity> entity)
                {
                    repo ??= Orm.GetRepository <TEntity>();
                    entity.Repository = repo;
                    entity.Attach();
                }
            }
        }
예제 #9
0
파일: AdmRoute.cs 프로젝트: 2881099/ojbk
        static AdmRoute()
        {
            #region 初始化菜单
            if (Orm.Select <AdmRoute>().Any() == false)
            {
                var adds = new[]
                {
                    new AdmRoute
                    {
                        Name    = "文档",
                        Sort    = 1,
                        Extdata = JsonConvert.SerializeObject(new { icon = "ios-book", href = "https://github.com/2881099/ojbk" }),
                    },
                    new AdmRoute
                    {
                        Name    = "QQ群",
                        Sort    = 2,
                        Extdata = JsonConvert.SerializeObject(new { icon = "_qq", path = "/join_qqgroup", name = "join_qqgroup", component = "@/view/join_qqgroup-page.vue" }),
                    },

                    new AdmRoute
                    {
                        Name    = "系统管理",
                        Sort    = 3,
                        Extdata = JsonConvert.SerializeObject(new { icon = "logo-buffer", path = "/sysadmin", name = "sysadmin" }),

                        Childs = new List <AdmRoute>(new []
                        {
                            new AdmRoute
                            {
                                Name    = "用户管理",
                                Sort    = 1,
                                Extdata = JsonConvert.SerializeObject(new { icon = "org_tree_page", path = "/authuser", name = "sysadmin_authuser", component = "@/view/sysadmin/authuser-page.vue" }),
                            },
                            new AdmRoute
                            {
                                Name    = "角色管理",
                                Sort    = 2,
                                Extdata = JsonConvert.SerializeObject(new { icon = "org_tree_page", path = "/authrole", name = "sysadmin_authrole", component = "@/view/sysadmin/authrole-page.vue" }),
                            },
                            new AdmRoute
                            {
                                Name    = "菜单管理",
                                Sort    = 3,
                                Extdata = JsonConvert.SerializeObject(new { icon = "org_tree_page", path = "/admroute", name = "sysadmin_admroute", component = "@/view/sysadmin/admroute-page.vue" }),
                            },
                            new AdmRoute
                            {
                                Name    = "权限管理",
                                Sort    = 4,
                                Extdata = JsonConvert.SerializeObject(new { icon = "org_tree_page", path = "/auth", name = "sysadmin_auth", component = "@/view/sysadmin/auth-page.vue" }),
                            },
                        })
                    },

                    new AdmRoute
                    {
                        Name    = "组织机构",
                        Sort    = 4,
                        Extdata = JsonConvert.SerializeObject(new { icon = "logo-buffer", path = "/organization", name = "organization" }),

                        Childs = new List <AdmRoute>(new []
                        {
                            new AdmRoute
                            {
                                Name    = "部门管理",
                                Sort    = 1,
                                Extdata = JsonConvert.SerializeObject(new { icon = "org_tree_page", path = "/department", name = "organization_department", component = "@/view/organization/department-page.vue" }),
                            },
                            new AdmRoute
                            {
                                Name    = "岗位管理",
                                Sort    = 2,
                                Extdata = JsonConvert.SerializeObject(new { icon = "org_tree_page", path = "/post", name = "organization_post", component = "@/view/organization/post-page.vue" }),
                            },
                            new AdmRoute
                            {
                                Name    = "员工管理",
                                Sort    = 3,
                                Extdata = JsonConvert.SerializeObject(new { icon = "org_tree_page", path = "/person", name = "organization_person", component = "@/view/organization/person-page.vue" }),
                            }
                        })
                    },
                };
                Orm.GetRepository <AdmRoute>().Insert(adds);
            }
            #endregion
        }
예제 #10
0
 /// <summary>
 /// 获取新的仓库对象
 /// </summary>
 /// <returns></returns>
 new public static BaseRepository <TEntity, TKey> GetRepository() => Orm.GetRepository <TEntity, TKey>();