/// <summary>
        /// 生成主键
        /// </summary>
        /// <param name="session"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public object Generate(ISessionImplementor session, object obj)
        {
            TypedEntityMetadata entityInfo = TypedEntityMetadata.GenerateEntityInfo(session.Factory, obj.GetType());

            return(PrimaryMaxIdGenerator.GetMaxId(entityInfo.TableName, entityInfo.IdColumnName, entityInfo.IdLength,
                                                  PrimaryMaxIdGenerator.GetIdYearMonth()).ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="searchExpression"></param>
        /// <param name="searchOrders"></param>
        /// <param name="parentItem"></param>
        public override System.Collections.IEnumerable GetData(ISearchExpression searchExpression, IList <ISearchOrder> searchOrders, object parentItem)
        {
            IList <T> list;
            object    masterItem = parentItem;

            if (masterItem != null)
            {
                if (masterItem.GetType() == typeof(T))
                {
                    list = new List <T>();
                    list.Add((T)masterItem);
                }
                else
                {
                    using (var rep = new Repository(this.RepositoryCfgName))
                    {
                        rep.BeginTransaction();
                        object id = EntityScript.GetPropertyValue(masterItem, TypedEntityMetadata.GenerateEntityInfo(rep.Session.SessionFactory, masterItem.GetType()).IdName);
                        NHibernate.ICriteria criteria = rep.Session.CreateCriteria(typeof(T))
                                                        .Add(NHibernate.Criterion.Expression.IdEq(id));
                        OnCriteriaCreated(criteria);
                        list = criteria.List <T>();

                        rep.CommitTransaction();
                    }
                }
            }
            else
            {
                list = new List <T>();
            }

            return(list);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="searchExpression"></param>
        /// <param name="searchOrders"></param>
        /// <param name="parentItem"></param>
        /// <returns></returns>
        public override System.Collections.IEnumerable GetData(ISearchExpression searchExpression, IList <ISearchOrder> searchOrders, object parentItem)
        {
            IList <S> list;
            var       parent = parentItem as T;

            if (parent != null && parent.ChildEntity != null)
            {
                if (base.IsReload || NHibernateHelper.IsProxy(parent.ChildEntity))
                {
                    //NHibernateHelper.Initialize(master.ChildEntity, master, reload);
                    //List<S> list = new List<S>();
                    //list.Add(master.ChildEntity);
                    using (var rep = new Repository(this.RepositoryCfgName))
                    {
                        rep.BeginTransaction();
                        object id = EntityScript.GetPropertyValue(parent, TypedEntityMetadata.GenerateEntityInfo(rep.Session.SessionFactory, typeof(T)).IdName);
                        NHibernate.ICriteria criteria = rep.Session.CreateCriteria(typeof(S))
                                                        .Add(NHibernate.Criterion.Expression.IdEq(id));
                        OnCriteriaCreated(criteria);
                        list = criteria.List <S>();

                        rep.CommitTransaction();
                    }
                    if (list.Count > 0)
                    {
                        parent.ChildEntity   = list[0];
                        list[0].ParentEntity = parent;
                    }
                }
                else
                {
                    list = new List <S>();
                    list.Add(parent.ChildEntity);
                }
            }
            else
            {
                list = new List <S>();
            }

            return(list);
        }