当前位置: 首页>>代码示例>>C#>>正文


C# List.ToArray方法代码示例

本文整理汇总了C#中NHibernate.Mapping.List.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# List.ToArray方法的具体用法?C# List.ToArray怎么用?C# List.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NHibernate.Mapping.List的用法示例。


在下文中一共展示了List.ToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetProperties

 public override PropertyDescriptorCollection GetProperties()
 {
     if (_properties == null)
     {
         bool hasEntityAttributes = false;
         _properties = base.GetProperties();
         var list = new List<PropertyDescriptor>();
         foreach (PropertyDescriptor descriptor in _properties)
         {
             List<Attribute> attrs = GetEntityMemberAttributes(descriptor).ToList();
             if (_metaDataAttributes.ContainsKey(descriptor.Name))
                 attrs.AddRange(_metaDataAttributes[descriptor.Name]);
             if (attrs.Any())
             {
                 hasEntityAttributes = true;
                 list.Add(new PropertyDescriptorWrapper(descriptor, attrs.ToArray()));
             }
             else
             {
                 list.Add(descriptor);
             }
         }
         if (hasEntityAttributes)
             _properties = new PropertyDescriptorCollection(list.ToArray(), true);
     }
     return _properties;
 }
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:27,代码来源:NHibernateTypeDescriptor.cs

示例2: GenerateSchemaDropScriptAuxiliaryDatabaseObjects

        public string[] GenerateSchemaDropScriptAuxiliaryDatabaseObjects(Func<IAuxiliaryDatabaseObject, bool> predicate)
        {
            Dialect dialect = Dialect.GetDialect(Properties);
            string defaultCatalog = PropertiesHelper.GetString("default_catalog", Properties, null);
            string defaultSchema = PropertiesHelper.GetString("default_schema", Properties, null);
            List<string> list = new List<string>();
            foreach (IAuxiliaryDatabaseObject obj2 in auxiliaryDatabaseObjects.Where(predicate))
            {
                if (obj2.AppliesToDialect(dialect))
                {
                    list.Add(obj2.SqlDropString(dialect,defaultCatalog, defaultSchema));
                }
            }

            return list.ToArray();
        }
开发者ID:ericklombardo,项目名称:Nuaguil.Net,代码行数:16,代码来源:NhExtConfiguration.cs

示例3: JoinedSubclassEntityPersister

		/// <summary>
		/// Constructs the NormalizedEntityPerister for the PersistentClass.
		/// </summary>
		/// <param name="persistentClass">The PersistentClass to create the EntityPersister for.</param>
		/// <param name="cache">The configured <see cref="ICacheConcurrencyStrategy" />.</param>
		/// <param name="factory">The SessionFactory that this EntityPersister will be stored in.</param>
		/// <param name="mapping">The mapping used to retrieve type information.</param>
		public JoinedSubclassEntityPersister(PersistentClass persistentClass, ICacheConcurrencyStrategy cache,
											 ISessionFactoryImplementor factory, IMapping mapping)
			: base(persistentClass, cache, factory)
		{
			#region DISCRIMINATOR

			if (persistentClass.IsPolymorphic)
			{
				try
				{
					discriminatorValue = persistentClass.SubclassId;
					discriminatorSQLString = discriminatorValue.ToString();
				}
				catch (Exception e)
				{
					throw new MappingException("Could not format discriminator value to SQL string", e);
				}
			}
			else
			{
				discriminatorValue = null;
				discriminatorSQLString = null;
			}

			if (OptimisticLockMode > Versioning.OptimisticLock.Version)
				throw new MappingException(string.Format("optimistic-lock=all|dirty not supported for joined-subclass mappings [{0}]", EntityName));

			#endregion

			#region MULTITABLES
			int idColumnSpan = IdentifierColumnSpan;

			List<string> tables = new List<string>();
			List<string[]> keyColumns = new List<string[]>();
			List<bool> cascadeDeletes = new List<bool>();
			IEnumerator<IKeyValue> kiter = persistentClass.KeyClosureIterator.GetEnumerator();
			foreach (Table tab in persistentClass.TableClosureIterator)
			{
				kiter.MoveNext();
				IKeyValue key = kiter.Current;
				string tabname = tab.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);
				tables.Add(tabname);

				List<string> keyCols = new List<string>(idColumnSpan);
				IEnumerable<Column> enumerableKCols = new SafetyEnumerable<Column>(key.ColumnIterator);
				foreach (Column kcol in enumerableKCols)
					keyCols.Add(kcol.GetQuotedName(factory.Dialect));

				keyColumns.Add(keyCols.ToArray());
				cascadeDeletes.Add(key.IsCascadeDeleteEnabled && factory.Dialect.SupportsCascadeDelete);				
			}
			naturalOrderTableNames = tables.ToArray();
			naturalOrderTableKeyColumns = keyColumns.ToArray();
			naturalOrderCascadeDeleteEnabled = cascadeDeletes.ToArray();

			List<string> subtables = new List<string>();
			List<bool> isConcretes = new List<bool>();
			keyColumns = new List<string[]>();
			foreach (Table tab in persistentClass.SubclassTableClosureIterator)
			{
				isConcretes.Add(persistentClass.IsClassOrSuperclassTable(tab));
				string tabname = tab.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);
				subtables.Add(tabname);
				List<string> key = new List<string>(idColumnSpan);
				foreach (Column column in tab.PrimaryKey.ColumnIterator)
					key.Add(column.GetQuotedName(factory.Dialect));

				keyColumns.Add(key.ToArray());				
			}
			subclassTableNameClosure = subtables.ToArray();
			subclassTableKeyColumnClosure = keyColumns.ToArray();
			isClassOrSuperclassTable = isConcretes.ToArray();

			constraintOrderedTableNames = new string[subclassTableNameClosure.Length];
			constraintOrderedKeyColumnNames = new string[subclassTableNameClosure.Length][];
			int currentPosition = 0;
			for (int i = subclassTableNameClosure.Length - 1; i >= 0; i--, currentPosition++)
			{
				constraintOrderedTableNames[currentPosition] = subclassTableNameClosure[i];
				constraintOrderedKeyColumnNames[currentPosition] = subclassTableKeyColumnClosure[i];
			}

			tableSpan = naturalOrderTableNames.Length;
			tableNames = Reverse(naturalOrderTableNames);
			tableKeyColumns = Reverse(naturalOrderTableKeyColumns);
			Reverse(subclassTableNameClosure, tableSpan);
			Reverse(subclassTableKeyColumnClosure, tableSpan);

			spaces = ArrayHelper.Join(tableNames, persistentClass.SynchronizedTables.ToArray());

			// Custom sql
			customSQLInsert = new SqlString[tableSpan];
			customSQLUpdate = new SqlString[tableSpan];
//.........这里部分代码省略.........
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:101,代码来源:JoinedSubclassEntityPersister.cs

示例4: GetImplementors


//.........这里部分代码省略.........
				return knownMap;
			}
			System.Type clazz = null;

			// NH Different implementation for performance: a class without at least a namespace sure can't be found by reflection
			if (entityOrClassName.IndexOf('.') > 0)
			{
				IEntityPersister checkPersister;
				// NH Different implementation: we have better performance checking, first of all, if we know the class
				// and take the System.Type directly from the persister (className have high probability to be entityName at least using Criteria or Linq)
				if (entityPersisters.TryGetValue(entityOrClassName, out checkPersister))
				{
					if(!checkPersister.EntityMetamodel.HasPocoRepresentation)
					{
						// we found the persister but it is a dynamic entity without class
						knownMap = new[] { entityOrClassName };
						entityNameImplementorsMap[entityOrClassName] = knownMap;
						return knownMap;
					}
					// NH : take care with this because we are forcing the Poco EntityMode
					clazz = checkPersister.GetMappedClass(EntityMode.Poco);
				}

				if (clazz == null)
				{
					try
					{
						clazz = ReflectHelper.ClassForFullNameOrNull(entityOrClassName);
					}
					catch (Exception)
					{
						clazz = null;
					}
				}
			}

			if (clazz == null)
			{
				// try to get the class from imported names
				string importedName = GetImportedClassName(entityOrClassName);
				if (importedName != null)
				{
					clazz = System.Type.GetType(importedName, false);
				}
			}

			if (clazz == null)
			{
				knownMap = new[] { entityOrClassName };
				entityNameImplementorsMap[entityOrClassName] = knownMap;
				return knownMap; //for a dynamic-class
			}

			var results = new List<string>();
			foreach (var q in entityPersisters.Values.OfType<IQueryable>())
			{
				string registeredEntityName = q.EntityName;
				// NH: as entity-name we are using the FullName but in HQL we allow just the Name, the class is mapped even when its FullName match the entity-name
				bool isMappedClass = entityOrClassName.Equals(registeredEntityName) || clazz.FullName.Equals(registeredEntityName);
				if (q.IsExplicitPolymorphism)
				{
					if (isMappedClass)
					{
						knownMap = new[] { registeredEntityName };
						entityNameImplementorsMap[entityOrClassName] = knownMap;
						return knownMap; // NOTE EARLY EXIT
					}
				}
				else
				{
					if (isMappedClass)
					{
						results.Add(registeredEntityName);
					}
					else
					{
						if (IsMatchingImplementor(entityOrClassName, clazz, q))
						{
							bool assignableSuperclass;
							if (q.IsInherited)
							{
								System.Type mappedSuperclass = GetEntityPersister(q.MappedSuperclass).GetMappedClass(EntityMode.Poco);
								assignableSuperclass = clazz.IsAssignableFrom(mappedSuperclass);
							}
							else
							{
								assignableSuperclass = false;
							}
							if (!assignableSuperclass)
							{
								results.Add(registeredEntityName);
							}
						}
					}
				}
			}
			knownMap = results.ToArray();
			entityNameImplementorsMap[entityOrClassName] = knownMap;
			return knownMap;
		}
开发者ID:prime,项目名称:nshibernate,代码行数:101,代码来源:SessionFactoryImpl.cs

示例5: UnionSubclassEntityPersister


//.........这里部分代码省略.........
			             	: (persistentClass.CustomSQLDeleteCheckStyle
			             	   ?? ExecuteUpdateResultCheckStyle.DetermineDefault(sql, callable));
			customSQLDelete = new SqlString[] { sql };
			deleteCallable = new bool[] { callable };
			deleteResultCheckStyles = new ExecuteUpdateResultCheckStyle[] { checkStyle };

			#endregion

			discriminatorValue = persistentClass.SubclassId;
			discriminatorSQLValue = persistentClass.SubclassId.ToString();

			#region PROPERTIES

			int subclassSpan = persistentClass.SubclassSpan + 1;
			subclassClosure = new string[subclassSpan];
			subclassClosure[0] = EntityName;

			#endregion

			#region SUBCLASSES

			subclassByDiscriminatorValue[persistentClass.SubclassId] = persistentClass.EntityName;
			if (persistentClass.IsPolymorphic)
			{
				int k = 1;
				foreach (Subclass sc in persistentClass.SubclassIterator)
				{
					subclassClosure[k++] = sc.EntityName;
					subclassByDiscriminatorValue[sc.SubclassId] = sc.EntityName;
				}
			}

			#endregion

			#region SPACES
			//TODO: i'm not sure, but perhaps we should exclude abstract denormalized tables?

			int spacesSize = 1 + persistentClass.SynchronizedTables.Count;
			spaces = new string[spacesSize];
			spaces[0] = tableName;
			IEnumerator<string> iSyncTab = persistentClass.SynchronizedTables.GetEnumerator();
			for (int i = 1; i < spacesSize; i++)
			{
				iSyncTab.MoveNext();
				spaces[i] = iSyncTab.Current;
			}

			HashedSet<string> subclassTables = new HashedSet<string>();
			foreach (Table table in persistentClass.SubclassTableClosureIterator)
			{
				subclassTables.Add(
					table.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName));
			}
			subclassSpaces = new string[subclassTables.Count];
			subclassTables.CopyTo(subclassSpaces, 0);

			subquery = GenerateSubquery(persistentClass, mapping);

			if (IsMultiTable)
			{
				int idColumnSpan = IdentifierColumnSpan;
				List<string> tableNames = new List<string>();
				List<string[]> keyColumns = new List<string[]>();
				if (!IsAbstract)
				{
					tableNames.Add(tableName);
					keyColumns.Add(IdentifierColumnNames);
				}
				foreach (Table tab in persistentClass.SubclassTableClosureIterator)
				{
					if (!tab.IsAbstractUnionTable)
					{
						string _tableName =
							tab.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);
						tableNames.Add(_tableName);

						List<string> key = new List<string>(idColumnSpan);
						foreach (Column column in tab.PrimaryKey.ColumnIterator)
							key.Add(column.GetQuotedName(factory.Dialect));

						keyColumns.Add(key.ToArray());
					}					
				}

				constraintOrderedTableNames = tableNames.ToArray();
				constraintOrderedKeyColumnNames = keyColumns.ToArray();
			}
			else
			{
				constraintOrderedTableNames = new string[] { tableName };
				constraintOrderedKeyColumnNames = new string[][] { IdentifierColumnNames };
			}
			#endregion

			InitLockers();

			InitSubclassPropertyAliasesMap(persistentClass);

			PostConstruct(mapping);
		}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:101,代码来源:UnionSubclassEntityPersister.cs

示例6: GenerateLazySelectString

		protected internal virtual SqlString GenerateLazySelectString()
		{
			if (!entityMetamodel.HasLazyProperties)
				return null;

			HashedSet<int> tableNumbers = new HashedSet<int>();
			List<int> columnNumbers = new List<int>();
			List<int> formulaNumbers = new List<int>();
			for (int i = 0; i < lazyPropertyNames.Length; i++)
			{
				// all this only really needs to consider properties
				// of this class, not its subclasses, but since we
				// are reusing code used for sequential selects, we
				// use the subclass closure
				int propertyNumber = GetSubclassPropertyIndex(lazyPropertyNames[i]);

				int tableNumber = GetSubclassPropertyTableNumber(propertyNumber);
				tableNumbers.Add(tableNumber);

				int[] colNumbers = subclassPropertyColumnNumberClosure[propertyNumber];
				for (int j = 0; j < colNumbers.Length; j++)
				{
					if (colNumbers[j] != -1)
					{
						columnNumbers.Add(colNumbers[j]);
					}
				}
				int[] formNumbers = subclassPropertyFormulaNumberClosure[propertyNumber];
				for (int j = 0; j < formNumbers.Length; j++)
				{
					if (formNumbers[j] != -1)
					{
						formulaNumbers.Add(formNumbers[j]);
					}
				}
			}

			if (columnNumbers.Count == 0 && formulaNumbers.Count == 0)
			{
				// only one-to-one is lazy fetched
				return null;
			}

			return RenderSelect(tableNumbers.ToArray(), columnNumbers.ToArray(), formulaNumbers.ToArray());
		}
开发者ID:rbirkby,项目名称:nhibernate-core,代码行数:45,代码来源:AbstractEntityPersister.cs

示例7: SingleTableEntityPersister

		public SingleTableEntityPersister(PersistentClass persistentClass, ICacheConcurrencyStrategy cache,
																			ISessionFactoryImplementor factory, IMapping mapping)
			: base(persistentClass, cache, factory)
		{
			#region CLASS + TABLE

			joinSpan = persistentClass.JoinClosureSpan + 1;
			qualifiedTableNames = new string[joinSpan];
			isInverseTable = new bool[joinSpan];
			isNullableTable = new bool[joinSpan];
			keyColumnNames = new string[joinSpan][];
			Table table = persistentClass.RootTable;
			qualifiedTableNames[0] =
				table.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);
			isInverseTable[0] = false;
			isNullableTable[0] = false;
			keyColumnNames[0] = IdentifierColumnNames;
			cascadeDeleteEnabled = new bool[joinSpan];

			// Custom sql
			customSQLInsert = new SqlString[joinSpan];
			customSQLUpdate = new SqlString[joinSpan];
			customSQLDelete = new SqlString[joinSpan];
			insertCallable = new bool[joinSpan];
			updateCallable = new bool[joinSpan];
			deleteCallable = new bool[joinSpan];
			insertResultCheckStyles = new ExecuteUpdateResultCheckStyle[joinSpan];
			updateResultCheckStyles = new ExecuteUpdateResultCheckStyle[joinSpan];
			deleteResultCheckStyles = new ExecuteUpdateResultCheckStyle[joinSpan];

			customSQLInsert[0] = persistentClass.CustomSQLInsert;
			insertCallable[0] = customSQLInsert[0] != null && persistentClass.IsCustomInsertCallable;
			insertResultCheckStyles[0] = persistentClass.CustomSQLInsertCheckStyle
																	 ?? ExecuteUpdateResultCheckStyle.DetermineDefault(customSQLInsert[0], insertCallable[0]);
			customSQLUpdate[0] = persistentClass.CustomSQLUpdate;
			updateCallable[0] = customSQLUpdate[0] != null && persistentClass.IsCustomUpdateCallable;
			updateResultCheckStyles[0] = persistentClass.CustomSQLUpdateCheckStyle
																	 ?? ExecuteUpdateResultCheckStyle.DetermineDefault(customSQLUpdate[0], updateCallable[0]);
			customSQLDelete[0] = persistentClass.CustomSQLDelete;
			deleteCallable[0] = customSQLDelete[0] != null && persistentClass.IsCustomDeleteCallable;
			deleteResultCheckStyles[0] = persistentClass.CustomSQLDeleteCheckStyle
																	 ?? ExecuteUpdateResultCheckStyle.DetermineDefault(customSQLDelete[0], deleteCallable[0]);

			#endregion

			#region JOINS
			int j = 1;
			foreach (Join join in persistentClass.JoinClosureIterator)
			{
				qualifiedTableNames[j] = join.Table.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);
				isInverseTable[j] = join.IsInverse;
				isNullableTable[j] = join.IsOptional;
				cascadeDeleteEnabled[j] = join.Key.IsCascadeDeleteEnabled && factory.Dialect.SupportsCascadeDelete;

				customSQLInsert[j] = join.CustomSQLInsert;
				insertCallable[j] = customSQLInsert[j] != null && join.IsCustomInsertCallable;
				insertResultCheckStyles[j] = join.CustomSQLInsertCheckStyle
																		 ??
																		 ExecuteUpdateResultCheckStyle.DetermineDefault(customSQLInsert[j], insertCallable[j]);
				customSQLUpdate[j] = join.CustomSQLUpdate;
				updateCallable[j] = customSQLUpdate[j] != null && join.IsCustomUpdateCallable;
				updateResultCheckStyles[j] = join.CustomSQLUpdateCheckStyle
																		 ??
																		 ExecuteUpdateResultCheckStyle.DetermineDefault(customSQLUpdate[j], updateCallable[j]);
				customSQLDelete[j] = join.CustomSQLDelete;
				deleteCallable[j] = customSQLDelete[j] != null && join.IsCustomDeleteCallable;
				deleteResultCheckStyles[j] = join.CustomSQLDeleteCheckStyle
																		 ??
																		 ExecuteUpdateResultCheckStyle.DetermineDefault(customSQLDelete[j], deleteCallable[j]);

				IEnumerable<Column> enumerableKeyCol = new SafetyEnumerable<Column>(join.Key.ColumnIterator);
				List<string> kcName = new List<string>(join.Key.ColumnSpan);
				foreach (Column col in enumerableKeyCol)
					kcName.Add(col.GetQuotedName(factory.Dialect));

				keyColumnNames[j] = kcName.ToArray();

				j++;
			}

			constraintOrderedTableNames = new string[qualifiedTableNames.Length];
			constraintOrderedKeyColumnNames = new string[qualifiedTableNames.Length][];
			for (int i = qualifiedTableNames.Length - 1, position = 0; i >= 0; i--, position++)
			{
				constraintOrderedTableNames[position] = qualifiedTableNames[i];
				constraintOrderedKeyColumnNames[position] = keyColumnNames[i];
			}

			spaces = ArrayHelper.Join(qualifiedTableNames, ArrayHelper.ToStringArray(persistentClass.SynchronizedTables));

			bool lazyAvailable = IsInstrumented(EntityMode.Poco);

			bool hasDeferred = false;
			List<string> subclassTables = new List<string>();
			List<string[]> joinKeyColumns = new List<string[]>();
			List<bool> isConcretes = new List<bool>();
			List<bool> isDeferreds = new List<bool>();
			List<bool> isInverses = new List<bool>();
			List<bool> isNullables = new List<bool>();
			List<bool> isLazies = new List<bool>();
//.........这里部分代码省略.........
开发者ID:juanplopes,项目名称:nhibernate,代码行数:101,代码来源:SingleTableEntityPersister.cs

示例8: GetImplementors

		/// <summary>
		/// Return the names of all persistent (mapped) classes that extend or implement the
		/// given class or interface, accounting for implicit/explicit polymorphism settings
		/// and excluding mapped subclasses/joined-subclasses of other classes in the result.
		/// </summary>
		public string[] GetImplementors(string className)
		{
			System.Type clazz = null;

			// NH Different implementation for performance: a class without at least a namespace sure can't be found by reflection
			if (className.IndexOf('.') > 0)
			{
				IEntityPersister checkPersister;
				// NH Different implementation: we have better performance checking, first of all, if we know the class
				// and take the System.Type directly from the persister (className have high probability to be entityName)
				if (entityPersisters.TryGetValue(className, out checkPersister))
				{
					if(!checkPersister.EntityMetamodel.HasPocoRepresentation)
					{
						// we found the persister but it is a dynamic entity without class
						return new[] { className };
					}
					// NH : take care with this because we are forcing the Poco EntityMode
					clazz = checkPersister.GetMappedClass(EntityMode.Poco);
				}

				if (clazz == null)
				{
					try
					{
						clazz = ReflectHelper.ClassForFullName(className);
					}
					catch (Exception)
					{
						clazz = null;
					}
				}
			}

			if (clazz == null)
			{
				return new[] {className}; //for a dynamic-class
			}

			List<string> results = new List<string>();
			foreach (IEntityPersister p in entityPersisters.Values)
			{
				IQueryable q = p as IQueryable;
				if (q != null)
				{
					string testClassName = q.EntityName;
					bool isMappedClass = className.Equals(testClassName);
					if (q.IsExplicitPolymorphism)
					{
						if (isMappedClass)
						{
							return new string[] {testClassName}; // NOTE EARLY EXIT
						}
					}
					else
					{
						if (isMappedClass)
						{
							results.Add(testClassName);
						}
						else
						{
							System.Type mappedClass = q.GetMappedClass(EntityMode.Poco);
							if (mappedClass != null && clazz.IsAssignableFrom(mappedClass))
							{
								bool assignableSuperclass;
								if (q.IsInherited)
								{
									System.Type mappedSuperclass = GetEntityPersister(q.MappedSuperclass).GetMappedClass(EntityMode.Poco);
									assignableSuperclass = clazz.IsAssignableFrom(mappedSuperclass);
								}
								else
								{
									assignableSuperclass = false;
								}
								if (!assignableSuperclass)
								{
									results.Add(testClassName);
								}
							}
						}
					}
				}
			}
			return results.ToArray();
		}
开发者ID:juanplopes,项目名称:nhibernate,代码行数:91,代码来源:SessionFactoryImpl.cs

示例9: GenerateSchemaCreationScript

		/// <summary>
		/// Generate DDL for creating tables
		/// </summary>
		/// <param name="dialect"></param>
		public string[] GenerateSchemaCreationScript(Dialect.Dialect dialect)
		{
			SecondPassCompile();

			string defaultCatalog = PropertiesHelper.GetString(Environment.DefaultCatalog, properties, null);
			string defaultSchema = PropertiesHelper.GetString(Environment.DefaultSchema, properties, null);

			List<string> script = new List<string>();

			foreach (Table table in TableMappings)
			{
				if (table.IsPhysicalTable)
				{
					script.Add(table.SqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
					script.AddRange(table.SqlCommentStrings(dialect, defaultCatalog, defaultSchema));
				}
			}

			foreach (Table table in TableMappings)
			{
				if (table.IsPhysicalTable)
				{
					if (!dialect.SupportsUniqueConstraintInCreateAlterTable)
					{
						foreach (UniqueKey uk in table.UniqueKeyIterator)
						{
							string constraintString = uk.SqlCreateString(dialect, mapping, defaultCatalog, defaultSchema);
							if (constraintString != null)
								script.Add(constraintString);
						}
					}

					foreach (Index index in table.IndexIterator)
						script.Add(index.SqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));

					if (dialect.HasAlterTable)
					{
						foreach (ForeignKey fk in table.ForeignKeyIterator)
						{
							if (fk.HasPhysicalConstraint)
								script.Add(fk.SqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
						}
					}
				}
			}

			IEnumerable<IPersistentIdentifierGenerator> pIDg = IterateGenerators(dialect);
			foreach (IPersistentIdentifierGenerator idGen in pIDg)
				script.AddRange(idGen.SqlCreateStrings(dialect));

			foreach (IAuxiliaryDatabaseObject auxDbObj in auxiliaryDatabaseObjects)
			{
				if (auxDbObj.AppliesToDialect(dialect))
				{
					script.Add(auxDbObj.SqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
				}
			}

			return script.ToArray();
		}
开发者ID:ray2006,项目名称:WCell,代码行数:64,代码来源:Configuration.cs

示例10: GenerateDropSchemaScript

		/// <summary>
		/// Generate DDL for dropping tables
		/// </summary>
		/// <seealso cref="NHibernate.Tool.hbm2ddl.SchemaExport" />
		public string[] GenerateDropSchemaScript(Dialect.Dialect dialect)
		{
			SecondPassCompile();

			string defaultCatalog = PropertiesHelper.GetString(Environment.DefaultCatalog, properties, null);
			string defaultSchema = PropertiesHelper.GetString(Environment.DefaultSchema, properties, null);

			List<string> script = new List<string>();

			// drop them in reverse order in case db needs it done that way...
			for (int i = auxiliaryDatabaseObjects.Count - 1; i >= 0; i--)
			{
				IAuxiliaryDatabaseObject auxDbObj = auxiliaryDatabaseObjects[i];
				if (auxDbObj.AppliesToDialect(dialect))
				{
					script.Add(auxDbObj.SqlDropString(dialect, defaultCatalog, defaultSchema));
				}
			}

			if (dialect.DropConstraints)
			{
				foreach (Table table in TableMappings)
				{
					if (table.IsPhysicalTable)
					{
						foreach (ForeignKey fk in table.ForeignKeyIterator)
						{
							if (fk.HasPhysicalConstraint)
								script.Add(fk.SqlDropString(dialect, defaultCatalog, defaultSchema));
						}
					}
				}
			}

			foreach (Table table in TableMappings)
			{
				if (table.IsPhysicalTable)
					script.Add(table.SqlDropString(dialect, defaultCatalog, defaultSchema));
			}

			IEnumerable<IPersistentIdentifierGenerator> pIDg = IterateGenerators(dialect);
			foreach (IPersistentIdentifierGenerator idGen in pIDg)
			{
				string dropString = idGen.SqlDropString(dialect);
				if (dropString != null)
					script.Add(dropString);
			}

			return script.ToArray();
		}
开发者ID:ray2006,项目名称:WCell,代码行数:54,代码来源:Configuration.cs

示例11: GetInvalidValues

        private InvalidValue[] GetInvalidValues(object entity, ISet circularityState)
        {
            if (entity == null || circularityState.Contains(entity))
            {
                return EMPTY_INVALID_VALUE_ARRAY; //Avoid circularity
            }
            else
            {
                circularityState.Add(entity);
            }

            if (!entityType.IsInstanceOfType(entity))
            {
                throw new ArgumentException("not an instance of: " + entity.GetType());
            }

            List<InvalidValue> results = new List<InvalidValue>();

            //Entity Validation
            foreach (IValidator validator in entityValidators)
            {
                var constraintContext = new ConstraintValidatorContext(null,defaultInterpolator.GetAttributeMessage(validator));
                if (!validator.IsValid(entity, constraintContext))
                {
                    new InvalidMessageTransformer(constraintContext, results, entityType, null, entity, entity, validator, defaultInterpolator, userInterpolator).Transform();
                }
            }

            results.AddRange(MembersValidation(entity, null));

            //Child validation
            for (int i = 0; i < childGetters.Count; i++)
            {
                MemberInfo member = childGetters[i];

                if (NHibernateUtil.IsPropertyInitialized(entity, member.Name))
                {
                    object value = TypeUtils.GetMemberValue(entity, member);

                    if (value != null && NHibernateUtil.IsInitialized(value))
                    {
                        MakeChildValidation(value, entity, member, circularityState, results);
                    }
                }
            }
            return results.ToArray();
        }
开发者ID:mpielikis,项目名称:nhibernate-contrib,代码行数:47,代码来源:ClassValidator.cs

示例12: GetPotentialInvalidValues

        /// <summary>
        /// Apply constraints of a particular property value of a entity type and return all the failures.
        /// The InvalidValue objects returns return null for InvalidValue#Entity and InvalidValue#RootEntity.
        /// Note: this is not recursive.
        /// </summary>
        /// <param name="propertyName">Name of the property or field to validate</param>
        /// <param name="value">Real value to validate. Is not an entity instance.</param>
        /// <returns></returns>
        public InvalidValue[] GetPotentialInvalidValues(string propertyName, object value)
        {
            List<InvalidValue> results = new List<InvalidValue>();

            int getterFound = 0;
            for (int i = 0; i < memberValidators.Count; i++)
            {
                MemberInfo getter = memberGetters[i];
                if (getter.Name.Equals(propertyName))
                {
                    getterFound++;
                    IValidator validator = memberValidators[i];

                    var constraintContext = new ConstraintValidatorContext(propertyName, defaultInterpolator.GetAttributeMessage(validator));

                    if (!validator.IsValid(value, null))
                        new InvalidMessageTransformer(constraintContext, results, entityType, propertyName, value, null, validator, defaultInterpolator, userInterpolator).Transform();

                }
            }

            if (getterFound == 0 && TypeUtils.GetPropertyOrField(entityType, propertyName) == null)
            {
                throw new TargetException(
                    string.Format("The property or field '{0}' was not found in class {1}", propertyName, entityType.FullName));
            }

            return results.ToArray();
        }
开发者ID:mpielikis,项目名称:nhibernate-contrib,代码行数:37,代码来源:ClassValidator.cs

示例13: GetDirectoryProperties


//.........这里部分代码省略.........
            List<IDictionary<string, string>> indexSpecificProps = new List<IDictionary<string, string>>();
            IDictionary<string, string> indexSpecificDefaultProps = new Dictionary<string, string>();

            foreach (KeyValuePair<string, string> entry in props)
            {
                string key = entry.Key;
                if (key.StartsWith(LUCENE_DEFAULT))
                {
                    defaultProperties[key.Substring(LUCENE_DEFAULT.Length)] = entry.Value;
                }
                else if (key.StartsWith(indexName))
                {
                    string suffixedKey = key.Substring(indexName.Length + 1);
                    int nextDoc = suffixedKey.IndexOf('.');
                    int index = -1;
                    if (nextDoc != -1)
                    {
                        string potentialNbr = suffixedKey.Substring(0, nextDoc);
                        if (!int.TryParse(potentialNbr, out index))
                        {
                            index = -1;
                        }
                    }

                    if (index != -1)
                    {
                        indexSpecificDefaultProps[suffixedKey] = entry.Value;
                    }
                    else
                    {
                        string finalKeyName = suffixedKey.Substring(nextDoc + 1);

                        // Ignore sharding strategy properties
                        if (!finalKeyName.StartsWith(SHARDING_STRATEGY))
                        {
                            EnsureListSize(indexSpecificProps, index + 1);
                            IDictionary<string, string> propertiesForIndex = indexSpecificProps[index];
                            if (propertiesForIndex == null)
                            {
                                propertiesForIndex = new Dictionary<string, string>();
                                indexSpecificProps[index] = propertiesForIndex;
                            }

                            propertiesForIndex[finalKeyName] = entry.Value;
                        }
                    }
                }
            }

            int nbrOfShards = -1;
            if (indexSpecificDefaultProps.ContainsKey(NBR_OF_SHARDS))
            {
                string nbrOfShardsString = indexSpecificDefaultProps[NBR_OF_SHARDS];
                if (!string.IsNullOrEmpty(nbrOfShardsString))
                {
                    if (!int.TryParse(nbrOfShardsString, out nbrOfShards))
                    {
                        throw new SearchException(indexName + "." + NBR_OF_SHARDS + " is not a number");
                    }
                }
            }

            // Original java doesn't copy properties from the defaults!
            foreach (KeyValuePair<string, string> prop in defaultProperties)
            {
                if (!indexSpecificDefaultProps.ContainsKey(prop.Key))
                {
                    indexSpecificDefaultProps.Add(prop);
                }
            }

            if (nbrOfShards <= 0 && indexSpecificDefaultProps.Count == 0)
            {
                // No Shard (A sharded subindex has to have at least one property)
                return new IDictionary<string, string>[] { indexSpecificDefaultProps };
            }

            // Sharded
            nbrOfShards = nbrOfShards > indexSpecificDefaultProps.Count ? nbrOfShards : indexSpecificDefaultProps.Count;
            EnsureListSize(indexSpecificProps, nbrOfShards);

            for (int index = 0; index < nbrOfShards; index++)
            {
                if (indexSpecificProps[index] == null)
                {
                    indexSpecificProps[index] = new Dictionary<string, string>(indexSpecificDefaultProps);
                }

                // Original java doesn't copy properties from the defaults!
                foreach (KeyValuePair<string, string> prop in indexSpecificDefaultProps)
                {
                    if (!indexSpecificProps[index].ContainsKey(prop.Key))
                    {
                        indexSpecificProps[index].Add(prop);
                    }
                }
            }

            return indexSpecificProps.ToArray();
        }
开发者ID:mpielikis,项目名称:nhibernate-contrib,代码行数:101,代码来源:DirectoryProviderFactory.cs

示例14: GetEntityMemberAttributes


//.........这里部分代码省略.........
                            var editable = new EditableAttribute(false);
                            if (id.Value is SimpleValue)
                                editable.AllowInitialValue =
                                    "assigned".Equals(((SimpleValue)id.Value).IdentifierGeneratorStrategy,
                                                      StringComparison.InvariantCultureIgnoreCase);
                            attributes.Add(editable);
                        }
                        break;
                    }
                }
            }
            Property member = _classMetadata.PropertyIterator.FirstOrDefault(x => x.Name == propertyDescriptor.Name);
            if (member == null)             //If ther's no mapping in nhibernate... 
                return attributes;
            //Required
            if ((!member.IsNullable) &&
                (propertyDescriptor.PropertyType.IsValueType &&
                 (propertyDescriptor.Attributes[typeof(RequiredAttribute)] == null)))
            {

                attributes.Add(new RequiredAttribute());
            }
            //Association
            if (member.Type.IsAssociationType &&
                (propertyDescriptor.Attributes[typeof(AssociationAttribute)] == null))
            {
                string name;
                string thisKey = "";
                string otherkey = "";
                if (member.Type.IsCollectionType)
                {
                    name = propertyDescriptor.ComponentType.FullName + "_" + member.Name;

                    if (member.Type.ReturnedClass.GetGenericArguments().Length != 1)
                    {
                        throw new Exception(
                            String.Format(
                                "The property {0} is not a generic collection as expected (like IList<T>)...",
                                member.Name));
                    }
                    Type targetClassType = member.Type.ReturnedClass.GetGenericArguments()[0];

                    foreach (Column col in _identifierCols)
                    {
                        thisKey += (thisKey != "" ? ", " : "") + col.Name;

                        //*****Naming convention****
                        //Here I'm assuming that the name of each field in the type that holds the foreign key observe
                        //the following structure: 

                        string field = member.Name.Replace(Inflector.Pluralize(targetClassType.Name), "") +
                            propertyDescriptor.ComponentType.Name + "_" + col.Name;

                        otherkey += (otherkey != "" ? ", " : "") + field;

                        if (targetClassType.GetProperties(BindingFlags.Public | BindingFlags.Instance).SingleOrDefault(x => x.Name == field) == null)
                            throw new Exception(String.Format("The class {0} doesn't contain a Property named {1}",
                                                targetClassType.Name, field));
                    }

                }
                else //Member is a class type
                {
                    //Key could be composite, cycle every identifier on "the other side"
                    PersistentClass otherMappingClass = _nhibernateConfiguration.GetClassMapping(member.Type.ReturnedClass);
                    foreach (Column col in otherMappingClass.Key.ColumnIterator)
                    {
                        //Naming Convention:
                        //The name of each foreign key field be MUST BE the name of the class field + "_" + the name of the key field in the targetclass
                        thisKey += (thisKey != "" ? ", " : "") + member.Name + "_" + col.Name;
                        otherkey += (otherkey != "" ? ", " : "") + col.Name;
                    }

                    //Check: this name MUST ALWAYS BE the same on the both side of a bi-directional association
                    name = member.Type.ReturnedClass.FullName
                        + "_" + Inflector.Pluralize(member.PersistentClass.NodeName);
                }

                //CHECK: When do you want to add an IncludeAttribute ?
                if (!_classMetadata.IsLazy)
                {
                    var incAttr = new IncludeAttribute();
                    attributes.Add(incAttr);
                }

                var attribute = new AssociationAttribute(
                    name,
                    thisKey,
                    otherkey
                    );
                Type fromParent = ForeignKeyDirection.ForeignKeyFromParent.GetType();
                attribute.IsForeignKey =
                    fromParent.IsInstanceOfType(((IAssociationType)member.Type).ForeignKeyDirection);
                attributes.Add(attribute);
            }
            //RoundtripOriginal
            if (member == _classMetadata.Version)
                attributes.Add(new RoundtripOriginalAttribute());
            return attributes.ToArray();
        }
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:101,代码来源:NHibernateTypeDescriptor.cs

示例15: EntityMetamodel


//.........这里部分代码省略.........

				if (properties[i].CascadeStyle != CascadeStyle.None)
				{
					foundCascade = true;
				}

				if (IndicatesCollection(properties[i].Type))
				{
					foundCollection = true;
				}

				if (propertyTypes[i].IsMutable && propertyCheckability[i])
				{
					foundMutable = true;
				}

				if (insertInclusions[i] != ValueInclusion.None)
				{
					foundInsertGeneratedValue = true;
				}

				if (updateInclusions[i] != ValueInclusion.None)
				{
					foundUpdateGeneratedValue = true;
				}

				MapPropertyToIndex(prop, i);
				i++;
			}

			if (naturalIdNumbers.Count == 0)
				naturalIdPropertyNumbers = null;
			else
				naturalIdPropertyNumbers = naturalIdNumbers.ToArray();

			hasCascades = foundCascade;
			hasInsertGeneratedValues = foundInsertGeneratedValue;
			hasUpdateGeneratedValues = foundUpdateGeneratedValue;
			hasNonIdentifierPropertyNamedId = foundNonIdentifierPropertyNamedId;

			versionPropertyIndex = tempVersionProperty;
			hasLazyProperties = hasLazy;

			if(hadLazyProperties && !hasLazy)
			{
				log.WarnFormat("Disabled lazy properies fetching for {0} beacuse it does not support lazy at the entity level", name);
			}
			if (hasLazy)
			{
				log.Info("lazy property fetching available for: " + name);
			}

			if(hadNoProxyRelations && !hasUnwrapProxyForProperties)
			{
				log.WarnFormat("Disabled ghost properies fetching for {0} beacuse it does not support lazy at the entity level", name);
			}
			if (hasUnwrapProxyForProperties)
			{
				log.Info("no-proxy property fetching available for: " + name);
			}

			mutable = persistentClass.IsMutable;

			if (!persistentClass.IsAbstract.HasValue)
			{
				// legacy behavior (with no abstract attribute specified)
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:67,代码来源:EntityMetamodel.cs


注:本文中的NHibernate.Mapping.List.ToArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。