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


C# IDbHelper.GetNHibernateType方法代码示例

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


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

示例1: PopulateClass

		private void PopulateClass(ModelClass cls, IDbConnection connection, IDbHelper helper)
		{
			if (cls != null && connection != null)
			{
				// Relations to this class (this class has the primary key)
				List<Relation> relationsTo = helper.GetPKRelations(cls);
				// If the other side of the relation (FK part) is not in our model, we won't
				// need the relation at all
				_manager.FilterPKRelations(relationsTo);

				// Relations from this class (this class has the foreign key)
				List<Relation> relationsFrom = helper.GetFKRelations(cls);
				// If the other side of the relation (PK part) is not in our model, we won't
				// need the relation at all
				_manager.FilterFKRelations(relationsFrom);

				// Properties
				List<Column> columns = helper.GetProperties(cls);
				if (columns != null && columns.Count > 0)
				{
					List<Column> specialColumns = new List<Column>();
					List<Column> ordinaryColumns = new List<Column>();
					foreach(Column column in columns)
					{
						if (column.Primary ||
						    (column.ForeignConstraints.Count > 0 &&
						     (Relation.GetCountOfMatchingRelations(relationsTo, column.ForeignConstraints) > 0 ||
						      Relation.GetCountOfMatchingRelations(relationsFrom, column.ForeignConstraints) > 0)
						    )
							)
						{
							specialColumns.Add(column);
						}
						else
						{
						    ordinaryColumns.Add(column);
						}
					}

                    if (_manager.SortProperties)
                    {
                        ordinaryColumns.Sort(new ColumnComparer());
                        specialColumns.Sort(new ColumnComparer());
                    }

					// Keys
					List<Column> primaryKeys = null;
					if (specialColumns.Count > 0)
					{
						primaryKeys = Column.FindPrimaryKeys(specialColumns);
						if (primaryKeys != null && primaryKeys.Count > 0)
						{
							// Create primary and composite keys
							if (primaryKeys.Count == 1)
							{
								ModelProperty keyProperty = _manager.NewPrimaryKey(cls, primaryKeys[0]);
								keyProperty.ColumnType = helper.GetNHibernateType(primaryKeys[0].DataType);
								SetGenerator(keyProperty);
							}
							else
							{
								string keyClassName = cls.Name + Common.CompositeClassNameSuffix;
								foreach(Column key in primaryKeys)
								{
									ModelProperty keyProperty = _manager.NewCompositeKey(cls, key, keyClassName);
									keyProperty.ColumnType = helper.GetNHibernateType(key.DataType);
									SetGenerator(keyProperty);
								}
							}
						}
					}

                    foreach (var column in ordinaryColumns)
                    {
                        _manager.NewProperty(cls, column).ColumnType = helper.GetNHibernateType(column.DataType);
                    }

					if (relationsTo != null && relationsTo.Count > 0)
					{
						foreach(Relation relation in relationsTo)
						{
							relation.PrimaryModelClass = cls;
						}
					}
					_relations.AddRange(relationsTo);

					if (relationsFrom != null && relationsFrom.Count > 0)
					{
						foreach(Relation relation in relationsFrom)
						{
							relation.ForeignModelClass = cls;
						}
						_relations.AddRange(relationsFrom);

						// To define many to many and one to one, we need to know the pattern of foreign keys.
						if (primaryKeys != null && primaryKeys.Count > 0)
						{
							foreach(Column key in primaryKeys)
							{
								Relation relation = Relation.GetForeginColumn(relationsFrom, key);
//.........这里部分代码省略.........
开发者ID:mgagne-atman,项目名称:Projects,代码行数:101,代码来源:ActiveRecordMapping.cs


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