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


C# PersistentClass.GetRecursiveProperty方法代码示例

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


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

示例1: BindPropertyResults

		private IDictionary<string, string[]> BindPropertyResults(string alias, HbmReturnDiscriminator discriminatorSchema,
			HbmReturnProperty[] returnProperties, PersistentClass pc)
		{
			Dictionary<string, string[]> propertyresults = new Dictionary<string, string[]>();
			// maybe a concrete SQLpropertyresult type, but Map is exactly what is required at the moment

			if (discriminatorSchema != null)
			{
				propertyresults["class"] = GetResultColumns(discriminatorSchema).ToArray();
			}

			List<HbmReturnProperty> properties = new List<HbmReturnProperty>();
			List<string> propertyNames = new List<string>();

			foreach (HbmReturnProperty returnPropertySchema in returnProperties ?? new HbmReturnProperty[0])
			{
				string name = returnPropertySchema.name;
				if (pc == null || name.IndexOf('.') == -1)
				{
					//if dotted and not load-collection nor return-join
					//regular property
					properties.Add(returnPropertySchema);
					propertyNames.Add(name);
				}
				else
				{
					// Reorder properties
					// 1. get the parent property
					// 2. list all the properties following the expected one in the parent property
					// 3. calculate the lowest index and insert the property

					int dotIndex = name.LastIndexOf('.');
					string reducedName = name.Substring(0, dotIndex);
					IValue value = pc.GetRecursiveProperty(reducedName).Value;
					IEnumerable<Mapping.Property> parentPropIter;
					if (value is Component)
					{
						Component comp = (Component) value;
						parentPropIter = comp.PropertyIterator;
					}
					else if (value is ToOne)
					{
						ToOne toOne = (ToOne) value;
						PersistentClass referencedPc = mappings.GetClass(toOne.ReferencedEntityName);
						if (toOne.ReferencedPropertyName != null)
							try
							{
								parentPropIter =
									((Component) referencedPc.GetRecursiveProperty(toOne.ReferencedPropertyName).Value).PropertyIterator;
							}
							catch (InvalidCastException e)
							{
								throw new MappingException("dotted notation reference neither a component nor a many/one to one", e);
							}
						else
							try
							{
								parentPropIter = ((Component) referencedPc.IdentifierProperty.Value).PropertyIterator;
							}
							catch (InvalidCastException e)
							{
								throw new MappingException("dotted notation reference neither a component nor a many/one to one", e);
							}
					}
					else
						throw new MappingException("dotted notation reference neither a component nor a many/one to one");
					bool hasFollowers = false;
					List<string> followers = new List<string>();
					foreach (Mapping.Property prop in parentPropIter)
					{
						string currentPropertyName = prop.Name;
						string currentName = reducedName + '.' + currentPropertyName;
						if (hasFollowers)
							followers.Add(currentName);
						if (name.Equals(currentName))
							hasFollowers = true;
					}

					int index = propertyNames.Count;
					int followersSize = followers.Count;
					for (int loop = 0; loop < followersSize; loop++)
					{
						string follower = followers[loop];
						int currentIndex = GetIndexOfFirstMatchingProperty(propertyNames, follower);
						index = currentIndex != -1 && currentIndex < index ? currentIndex : index;
					}
					propertyNames.Insert(index, name);
					properties.Insert(index, returnPropertySchema);
				}
			}

			var uniqueReturnProperty = new HashSet<string>();
			foreach (HbmReturnProperty returnPropertySchema in properties)
			{
				string name = returnPropertySchema.name;
				if ("class".Equals(name))
					throw new MappingException(
						"class is not a valid property name to use in a <return-property>, use <return-discriminator> instead"
						);
				//TODO: validate existing of property with the chosen name. (secondpass )
//.........这里部分代码省略.........
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:101,代码来源:ResultSetMappingBinder.cs

示例2: BindPropertyResults

        private IDictionary BindPropertyResults(string alias, HbmReturnDiscriminator discriminatorSchema,
            HbmReturnProperty[] returnProperties, PersistentClass pc)
        {
            IDictionary propertyresults = new Hashtable();
            // maybe a concrete SQLpropertyresult type, but Map is exactly what is required at the moment

            if (discriminatorSchema != null)
            {
                ArrayList resultColumns = GetResultColumns(discriminatorSchema);
                propertyresults["class"] = ArrayHelper.ToStringArray(resultColumns);
            }

            IList properties = new ArrayList();
            IList propertyNames = new ArrayList();

            foreach (HbmReturnProperty returnPropertySchema in returnProperties ?? new HbmReturnProperty[0])
            {
                String name = returnPropertySchema.name;
                if (pc == null || name.IndexOf('.') == -1)
                {
                    //if dotted and not load-collection nor return-join
                    //regular property
                    properties.Add(returnPropertySchema);
                    propertyNames.Add(name);
                }
                else
                {
                    // Reorder properties
                    // 1. get the parent property
                    // 2. list all the properties following the expected one in the parent property
                    // 3. calculate the lowest index and insert the property

                    int dotIndex = name.LastIndexOf('.');
                    string reducedName = name.Substring(0, dotIndex);
                    IValue value = pc.GetRecursiveProperty(reducedName).Value;
                    IEnumerable<Mapping.Property> parentPropIter;
                    if (value is Component)
                    {
                        Component comp = (Component) value;
                        parentPropIter = comp.PropertyIterator;
                    }
                    else if (value is ToOne)
                    {
                        ToOne toOne = (ToOne) value;
                        PersistentClass referencedPc = mappings.GetClass(toOne.ReferencedEntityName);
                        if (toOne.ReferencedPropertyName != null)
                            try
                            {
                                parentPropIter =
                                    ((Component) referencedPc.GetRecursiveProperty(toOne.ReferencedPropertyName).Value).PropertyIterator;
                            }
                            catch (InvalidCastException e)
                            {
                                throw new MappingException("dotted notation reference neither a component nor a many/one to one", e);
                            }
                        else
                            try
                            {
                                parentPropIter = ((Component) referencedPc.IdentifierProperty.Value).PropertyIterator;
                            }
                            catch (InvalidCastException e)
                            {
                                throw new MappingException("dotted notation reference neither a component nor a many/one to one", e);
                            }
                    }
                    else
                        throw new MappingException("dotted notation reference neither a component nor a many/one to one");
                    bool hasFollowers = false;
                    IList followers = new ArrayList();
                    foreach (Mapping.Property prop in parentPropIter)
                    {
                        String currentPropertyName = prop.Name;
                        String currentName = reducedName + '.' + currentPropertyName;
                        if (hasFollowers)
                            followers.Add(currentName);
                        if (name.Equals(currentName))
                            hasFollowers = true;
                    }

                    int index = propertyNames.Count;
                    int followersSize = followers.Count;
                    for (int loop = 0; loop < followersSize; loop++)
                    {
                        String follower = (String) followers[loop];
                        int currentIndex = GetIndexOfFirstMatchingProperty(propertyNames, follower);
                        index = currentIndex != -1 && currentIndex < index ? currentIndex : index;
                    }
                    propertyNames.Insert(index, name);
                    properties.Insert(index, returnPropertySchema);
                }
            }

            ISet uniqueReturnProperty = new HashedSet();
            foreach (HbmReturnProperty returnPropertySchema in properties)
            {
                string name = returnPropertySchema.name;
                if ("class".Equals(name))
                    throw new MappingException(
                        "class is not a valid property name to use in a <return-property>, use <return-discriminator> instead"
                        );
//.........这里部分代码省略.........
开发者ID:zibler,项目名称:zibler,代码行数:101,代码来源:ResultSetMappingBinder.cs


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