/// <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()); }
/// <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); }
/// <summary> /// 生成EntityInfo信息 /// </summary> /// <param name="sessionFactory"></param> /// <param name="type"></param> /// <returns></returns> public static TypedEntityMetadata GenerateEntityInfo(ISessionFactory sessionFactory, Type type) { if (!m_entityInfos.ContainsKey(type)) { m_entityInfos[type] = new TypedEntityMetadata(sessionFactory, type); } return(m_entityInfos[type]); }
/// <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); }
/// <summary> /// 生成EntityInfo信息 /// </summary> /// <param name="sessionFactory"></param> /// <param name="type"></param> /// <returns></returns> public static TypedEntityMetadata GenerateEntityInfo(ISessionFactory sessionFactory, Type type) { if (!m_entityInfos.ContainsKey(type)) { m_entityInfos[type] = new TypedEntityMetadata(sessionFactory, type); } return m_entityInfos[type]; }