/// <summary> /// 获取指定持久化类的指定个数的主键值。 /// </summary> /// <param name="type">持久化类的类型。</param> /// <param name="count">要获取的主键值的个数。</param> /// <returns>主键集合。</returns> public static string[] GetNextId(Type type, int count) { if (count > 0) { //镜像服务器标志。 string MirrorTag = ConfigurationManager.AppSettings["MirrorTag"]; if (MirrorTag.Length > 5) { return(null); } //获取当前PO在数据库中对应的表名。 NHibernate.Mapping.PersistentClass pc = Db.Configuration.GetClassMapping(type); string tableName = pc.Table.Name; int iNextId = 0; lock (SyncLocks[type]) { iNextId = InnerGetNextId(tableName, count); } string[] Ids = new string[count]; for (int i = 0; i < count; i++) { int id = iNextId + i; Ids[i] = MirrorTag + id.ToString("d10"); } return(Ids); } else { return(null); } }
NHibernate.Mapping.Property GetPropertyOrNull(NHibernate.Mapping.PersistentClass classMapping, string propertyName) { try { return(classMapping?.GetProperty(propertyName)); } catch (NHibernate.MappingException) { return(null); } }
/// <summary> /// 获取指定持久化类的下一个主键值。 /// </summary> /// <param name="type">持久化类的类型。</param> /// <returns>主键。</returns> public static string GetNextId(Type type) { //获取当前PO在数据库中对应的表名。 NHibernate.Mapping.PersistentClass pc = Db.Configuration.GetClassMapping(type); string tableName = pc.Table.Name; int iNextId = 0; lock (SyncLocks[type]) { iNextId = InnerGetNextId(tableName, 1); } return(MirrorTag + iNextId.ToString("d10")); }