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


C# ISessionFactory.GetClassMetadata方法代码示例

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


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

示例1: GetPropertyType

		public static IType GetPropertyType(
			ISessionFactory sessionFactory,
			Type classType,
			string propertyName)
		{
			string[] properties = propertyName.Split(new char[] { '.' });
			IClassMetadata currentMetadata = sessionFactory.GetClassMetadata(classType);
			IType currentType = null;
			foreach (string s in properties)
			{
				// get metadata from type, if necessary
				if (currentMetadata == null)
				{
					currentMetadata = sessionFactory.GetClassMetadata(currentType.ReturnedClass);
				}
				// get type from metadata
				if ("id".Equals(s))
				{
					currentType = currentMetadata.IdentifierType;
				}
				else
				{
					currentType = currentMetadata.GetPropertyType(s);
				}

				currentMetadata = null;
			}
			return currentType;
		}
开发者ID:devmicrominds,项目名称:HIS-Project,代码行数:29,代码来源:NHibernateUtils.cs

示例2: IsDynamicComponentDictionaryGetter

		public static bool IsDynamicComponentDictionaryGetter(MethodInfo method, Expression targetObject, IEnumerable<Expression> arguments, ISessionFactory sessionFactory, out string memberName)
		{
			memberName = null;

			// A dynamic component must be an IDictionary with a string key.

			if (method.Name != "get_Item" || !typeof(IDictionary).IsAssignableFrom(targetObject.Type))
				return false;

			var key = arguments.First() as ConstantExpression;
			if (key == null || key.Type != typeof(string))
				return false;

			// The potential member name
			memberName = (string)key.Value;

			// Need the owning member (the dictionary).
			var member = targetObject as MemberExpression;
			if (member == null)
				return false;

			var memberPath = member.Member.Name;
			var metaData = sessionFactory.GetClassMetadata(member.Expression.Type);

			//Walk backwards if the owning member is not a mapped class (i.e a possible Component)
			targetObject = member.Expression;
			while (metaData == null && targetObject != null &&
			       (targetObject.NodeType == ExpressionType.MemberAccess || targetObject.NodeType == ExpressionType.Parameter ||
			        targetObject.NodeType == QuerySourceReferenceExpression.ExpressionType))
			{
				System.Type memberType;
				if (targetObject.NodeType == QuerySourceReferenceExpression.ExpressionType)
				{
					var querySourceExpression = (QuerySourceReferenceExpression) targetObject;
					memberType = querySourceExpression.Type;
				}
				else if (targetObject.NodeType == ExpressionType.Parameter)
				{
					var parameterExpression = (ParameterExpression) targetObject;
					memberType = parameterExpression.Type;
				}
				else //targetObject.NodeType == ExpressionType.MemberAccess
				{
					var memberExpression = ((MemberExpression) targetObject);
					memberPath = memberExpression.Member.Name + "." + memberPath;
					memberType = memberExpression.Type;
					targetObject = memberExpression.Expression;
				}
				metaData = sessionFactory.GetClassMetadata(memberType);
			}

			if (metaData == null)
				return false;

			// IDictionary can be mapped as collection or component - is it mapped as a component?
			var propertyType = metaData.GetPropertyType(memberPath);
			return (propertyType != null && propertyType.IsComponentType);
		}
开发者ID:jlevitt,项目名称:nhibernate-core,代码行数:58,代码来源:VisitorUtil.cs

示例3: IsDynamicComponentDictionaryGetter

		public static bool IsDynamicComponentDictionaryGetter(MethodInfo method, Expression targetObject, IEnumerable<Expression> arguments, ISessionFactory sessionFactory, out string memberName)
		{
			memberName = null;

			// A dynamic component must be an IDictionary with a string key.

			if (method.Name != "get_Item" || !typeof(IDictionary).IsAssignableFrom(targetObject.Type))
				return false;

			var key = arguments.First() as ConstantExpression;
			if (key == null || key.Type != typeof(string))
				return false;

			// The potential member name
			memberName = (string)key.Value;

			// Need the owning member (the dictionary).
			var member = targetObject as MemberExpression;
			if (member == null)
				return false;

			var metaData = sessionFactory.GetClassMetadata(member.Expression.Type);
			if (metaData == null)
				return false;

			// IDictionary can be mapped as collection or component - is it mapped as a component?
			var propertyType = metaData.GetPropertyType(member.Member.Name);
			return (propertyType != null && propertyType.IsComponentType);
		}
开发者ID:snbbgyth,项目名称:WorkFlowEngine,代码行数:29,代码来源:VisitorUtil.cs

示例4: Model

        public Model(ISessionFactory sessionfactory, Type type)
        {
            if (sessionfactory == null) throw new ArgumentNullException("sessionfactory");
            if (type == null) throw new ArgumentNullException("type");

            IsComponent = false;
            Type = type;
            Metadata = sessionfactory.GetClassMetadata(Type);
            Properties = new Dictionary<string, IType>();
            Components = new Dictionary<string, Model>();
            BelongsTos = new Dictionary<string, ManyToOneType>();
            OneToOnes = new Dictionary<string, OneToOneType>();
            Anys = new Dictionary<string, AnyType>();
            HasManys = new Dictionary<string, Collection>();
            HasAndBelongsToManys = new Dictionary<string, Collection>();

            PrimaryKey = new KeyValuePair<string, IType>(Metadata.IdentifierPropertyName, Metadata.IdentifierType);
            foreach (var name in Metadata.PropertyNames) {
                var prop = Metadata.GetPropertyType(name);
                CategorizeProperty(sessionfactory, prop, name);
            }
            Properties = new ReadOnlyDictionary<string, IType>(Properties);
            Components = new ReadOnlyDictionary<string, Model>(Components);
            BelongsTos = new ReadOnlyDictionary<string, ManyToOneType>(BelongsTos);
            OneToOnes = new ReadOnlyDictionary<string, OneToOneType>(OneToOnes);
            Anys = new ReadOnlyDictionary<string, AnyType>(Anys);
            HasManys = new ReadOnlyDictionary<string, Collection>(HasManys);
            HasAndBelongsToManys = new ReadOnlyDictionary<string, Collection>(HasAndBelongsToManys);
        }
开发者ID:shosca,项目名称:ActiveRecord,代码行数:29,代码来源:Model.cs

示例5: ApplyExpansions

        /// <summary>
        /// Add the Fetch clauses to the query according to the given expand paths, using the ICriteria API
        /// </summary>
        /// <param name="criteria">The query to expand</param>
        /// <param name="expandPaths">The names of the properties to expand.  May include nested paths of the form "Property/SubProperty"</param>
        /// <param name="sessionFactory">Provides the NHibernate metadata for the classes</param>
        /// <param name="expandMap">If provided, will be populated with the names of the expanded properties for each type.</param>
        /// <returns></returns>
        public static ICriteria ApplyExpansions(ICriteria criteria, string[] expandPaths, ISessionFactory sessionFactory, IDictionary<Type, List<string>> expandMap = null)
        {
            if (criteria == null) throw new ArgumentException("Criteria cannot be null");

            if (!expandPaths.Any()) throw new ArgumentException("Expansion Paths cannot be null");

            foreach (string expand in expandPaths)
            {
                // We always start with the resulting element type
                var currentType = criteria.GetRootEntityTypeIfAvailable();
                var dotpath = expand.Replace('/', '.');
                criteria.SetFetchMode(dotpath, FetchMode.Eager);

                // Add the types and properties to the expandMap so they will be serialized
                foreach (string seg in expand.Split('/'))
                {
                    if (expandMap != null && !expandMap.ContainsKey(currentType))
                        expandMap.Add(currentType, new List<string>());

                    IClassMetadata metadata = sessionFactory.GetClassMetadata(currentType);
                    if (metadata == null)
                    {
                        throw new ArgumentException("Type '" + currentType + "' not recognized as a valid type for this Context");
                    }

                    // Gather information about the property
                    var propInfo = currentType.GetProperty(seg);

                    if (propInfo == null)
                    {
                        throw new ArgumentException("Type '" + currentType.Name + "' does not have property '" + seg + "'");
                    }
                    if (expandMap != null) expandMap[currentType].Add(seg);
                    var propType = propInfo.PropertyType;

                    currentType = propType;
                }
            }

            return criteria;
        }
开发者ID:jgarverick,项目名称:Breeze,代码行数:49,代码来源:NHEagerFetch.cs

示例6: GetIdentifier

		private static Expression GetIdentifier(ISessionFactory sessionFactory, Expression expression)
		{
			var classMetadata = sessionFactory.GetClassMetadata(expression.Type);
			if (classMetadata == null)
				return Expression.Constant(null);

            var propertyName=classMetadata.IdentifierPropertyName;
            NHibernate.Type.EmbeddedComponentType componentType;
            if (propertyName == null && (componentType=classMetadata.IdentifierType as NHibernate.Type.EmbeddedComponentType)!=null)
            {
                //The identifier is an embedded composite key. We only need one property from it for a null check
                propertyName = componentType.PropertyNames.First();
            }

            return ConvertToObject(Expression.PropertyOrField(expression, propertyName));
		}
开发者ID:whut,项目名称:nhibernate-core,代码行数:16,代码来源:NestedSelectRewriter.cs

示例7: GetIdentifier

		static Expression GetIdentifier(ISessionFactory sessionFactory, IEnumerable<ExpressionHolder> expressions, ExpressionHolder e)
		{
			foreach (var holders in expressions)
			{
				if (holders.Tuple == e.Tuple)
				{
					var memberExpression = holders.Expression as MemberExpression;
					if (memberExpression != null)
					{
						var expression = memberExpression.Expression;
						var classMetadata = sessionFactory.GetClassMetadata(expression.Type);
						if (classMetadata != null)
						{
							return ConvertToObject(Expression.PropertyOrField(expression, classMetadata.IdentifierPropertyName));
						}
					}
				}
			}
			return Expression.Constant(null);
		}
开发者ID:nikson,项目名称:nhibernate-core,代码行数:20,代码来源:NestedSelectRewriter.cs

示例8: GetIdentifier

		private static Expression GetIdentifier(ISessionFactory sessionFactory, Expression expression)
		{
			var classMetadata = sessionFactory.GetClassMetadata(expression.Type);
			if (classMetadata == null)
				return Expression.Constant(null);
			
			return ConvertToObject(Expression.PropertyOrField(expression, classMetadata.IdentifierPropertyName));
		}
开发者ID:thilaknathen,项目名称:nhibernate-core,代码行数:8,代码来源:NestedSelectRewriter.cs

示例9: GetId

        /// <summary>
        /// GetId
        /// </summary>
        /// <param name="sessionFactory"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static object GetId(ISessionFactory sessionFactory, object entity)
        {
            if (entity == null)
            {
                return null;
            }
            Type entityType = entity.GetType();

            NHibernate.Metadata.IClassMetadata entityMeta = sessionFactory.GetClassMetadata(entityType);
            if (entityMeta != null)
            {
                return entityMeta.GetIdentifier(entity, EntityMode.Map);
            }
            else
            {
                return null;
            }
        }
开发者ID:urmilaNominate,项目名称:mERP-framework,代码行数:24,代码来源:NHibernateHelper.cs

示例10: GetPropertyType

        /// <summary>
        /// ����Metadata�õ���������(Path�ԣ�����.�ָ�����Collection���򷵻�Collection���ڲ�Type��
        /// </summary>
        /// <param name="sessionFactory"></param>
        /// <param name="type"></param>
        /// <param name="fullPropertyName"></param>
        /// <param name="hasCollection"></param>
        /// <returns></returns>
        public static Type GetPropertyType(ISessionFactory sessionFactory, Type type, string fullPropertyName, out bool hasCollection)
        {
            hasCollection = false;
            if (string.IsNullOrEmpty(fullPropertyName))
                return null;
            string dictKey = type.ToString() + "#" + fullPropertyName;

            lock (s_propertyTypesHasCollection)
            {
                if (!s_propertyTypes.ContainsKey(dictKey))
                {
                    NHibernate.Metadata.IClassMetadata classMetadata = sessionFactory.GetClassMetadata(type);
                    if (classMetadata == null)
                    {
                        throw new NotSupportedException("There is no Metadata of type " + type.ToString());
                    }
                    NHibernate.Type.IType destType = null;
                    Type innerType = null;

                    NHibernate.Type.ComponentType componentType = null;
                    string[] ss = fullPropertyName.Split(new char[] { ':', '.' });
                    for (int i = 0; i < ss.Length; ++i)
                    {
                        TryRemoveJoinTypeChar(ref ss[i]);
                        if (componentType == null)
                        {
                            destType = classMetadata.GetPropertyType(ss[i]);
                        }
                        else
                        {
                            for (int j = 0; j < componentType.PropertyNames.Length; ++j)
                            {
                                if (componentType.PropertyNames[j] == ss[i])
                                {
                                    destType = componentType.Subtypes[j];
                                    break;
                                }
                            }
                        }
                        componentType = destType as NHibernate.Type.ComponentType;

                        if (componentType == null)
                        {
                            if (destType.IsCollectionType)
                            {
                                //System.Collections.Generic.IList`1[[Hd.Model.Jk2.��������ҵ����, Hd.Model.Jk2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
                                innerType = Feng.Utils.ReflectionHelper.GetGenericUnderlyingType(destType.ReturnedClass);
                                classMetadata = sessionFactory.GetClassMetadata(innerType);

                                hasCollection = true;
                            }
                            else
                            {
                                classMetadata = sessionFactory.GetClassMetadata(destType.ReturnedClass);
                            }
                        }
                    }

                    if (!destType.IsCollectionType)
                    {
                        s_propertyTypes[dictKey] = destType.ReturnedClass;
                    }
                    else
                    {
                        s_propertyTypes[dictKey] = innerType;
                    }

                    s_propertyTypesHasCollection[dictKey] = hasCollection;
                }

                hasCollection = s_propertyTypesHasCollection[dictKey];
                return s_propertyTypes[dictKey];
            }
        }
开发者ID:urmilaNominate,项目名称:mERP-framework,代码行数:82,代码来源:NHibernateHelper.cs

示例11: GetOnetoManyPropertyName

        /// <summary>
        /// ���MasterDetail�µ�Detail Property Name
        /// </summary>
        /// <param name="sessionFactory"></param>
        /// <param name="masterType"></param>
        /// <param name="detailType"></param>
        /// <returns></returns>
        public static string GetOnetoManyPropertyName(ISessionFactory sessionFactory, Type masterType, Type detailType)
        {
            if (!s_collectionPropertyNames.ContainsKey(detailType))
            {
                s_collectionPropertyNames[detailType] = new Dictionary<Type, string>();
            }
            if (!s_collectionPropertyNames[detailType].ContainsKey(masterType))
            {
                NHibernate.Metadata.IClassMetadata metadata = sessionFactory.GetClassMetadata(detailType.FullName);

                for (int i = 0; i < metadata.PropertyTypes.Length; ++i)
                {
                    NHibernate.Type.ManyToOneType manyToOneType = metadata.PropertyTypes[i] as NHibernate.Type.ManyToOneType;
                    if (manyToOneType != null && manyToOneType.ReturnedClass == masterType)
                    {
                        s_collectionPropertyNames[detailType][masterType] = metadata.PropertyNames[i];
                        break;
                    }

                    NHibernate.Type.OneToOneType oneToOneType = metadata.PropertyTypes[i] as NHibernate.Type.OneToOneType;
                    if (oneToOneType != null && oneToOneType.ReturnedClass == masterType)
                    {
                        s_collectionPropertyNames[detailType][masterType] = metadata.PropertyNames[i];
                        break;
                    }
                }
            }

            return s_collectionPropertyNames[detailType][masterType];
        }
开发者ID:urmilaNominate,项目名称:mERP-framework,代码行数:37,代码来源:NHibernateHelper.cs

示例12: ApplyExpansions

        /// <summary>
        /// Add the Fetch clauses to the query according to the given expand paths
        /// </summary>
        /// <param name="queryable">The query to expand</param>
        /// <param name="expandPaths">The names of the properties to expand.  May include nested paths of the form "Property/SubProperty"</param>
        /// <param name="sessionFactory">Provides the NHibernate metadata for the classes</param>
        /// <param name="expandMap">If provided, will be populated with the names of the expanded properties for each type.</param>
        /// <returns></returns>
        public static IQueryable ApplyExpansions(IQueryable queryable, string[] expandPaths, ISessionFactory sessionFactory, IDictionary<Type, List<string>> expandMap = null)
        {
            if (queryable == null) throw new ArgumentException("Query cannot be null");

            var nHibQuery = queryable.Provider as DefaultQueryProvider;
            if (nHibQuery == null) throw new ArgumentException("Expansion only supported on INHibernateQueryable queries");

            if (!expandPaths.Any()) throw new ArgumentException("Expansion Paths cannot be null");

            var currentQueryable = queryable;
            foreach (string expand in expandPaths)
            {
                // We always start with the resulting element type
                var currentType = currentQueryable.ElementType;
                var isFirstFetch = true;
                foreach (string seg in expand.Split('/'))
                {
                    if (expandMap != null && !expandMap.ContainsKey(currentType))
                        expandMap.Add(currentType, new List<string>());

                    IClassMetadata metadata = sessionFactory.GetClassMetadata(currentType);
                    if (metadata == null)
                    {
                        throw new ArgumentException("Type '" + currentType + "' not recognized as a valid type for this Context");
                    }

                    // Gather information about the property
                    var propInfo = currentType.GetProperty(seg);

                    if (propInfo == null)
                    {
                        throw new ArgumentException("Type '" + currentType.Name + "' does not have property '" + seg + "'");
                    }
                    if (expandMap != null) expandMap[currentType].Add(seg);
                    var propType = propInfo.PropertyType;
                    var metaPropType = metadata.GetPropertyType(seg);

                    // When this is the first segment of a path, we have to use Fetch instead of ThenFetch
                    var propFetchFunctionName = (isFirstFetch ? "Fetch" : "ThenFetch");

                    // The delegateType is a type for the lambda creation to create the correct return value
                    System.Type delegateType;

                    if (metaPropType.IsCollectionType)
                    {
                        // We have to use "FetchMany" or "ThenFetchMany" when the target property is a collection
                        propFetchFunctionName += "Many";

                        // We only support IList<T> or something similar
                        propType = propType.GetGenericArguments().Single();
                        delegateType = typeof(Func<,>).MakeGenericType(currentType,
                                                                        typeof(IEnumerable<>).MakeGenericType(propType));
                    }
                    else
                    {
                        delegateType = typeof(Func<,>).MakeGenericType(currentType, propType);
                    }

                    // Get the correct extension method (Fetch, FetchMany, ThenFetch, or ThenFetchMany)
                    var fetchMethodInfo = typeof(EagerFetchingExtensionMethods).GetMethod(propFetchFunctionName,
                                                                                      BindingFlags.Static |
                                                                                      BindingFlags.Public |
                                                                                      BindingFlags.InvokeMethod);
                    var fetchMethodTypes = new List<System.Type>();
                    fetchMethodTypes.AddRange(currentQueryable.GetType().GetGenericArguments().Take(isFirstFetch ? 1 : 2));
                    fetchMethodTypes.Add(propType);
                    fetchMethodInfo = fetchMethodInfo.MakeGenericMethod(fetchMethodTypes.ToArray());

                    // Create an expression of type new delegateType(x => x.{seg.Name})
                    var exprParam = System.Linq.Expressions.Expression.Parameter(currentType, "x");
                    var exprProp = System.Linq.Expressions.Expression.Property(exprParam, seg);
                    var exprLambda = System.Linq.Expressions.Expression.Lambda(delegateType, exprProp,
                                                                               new System.Linq.Expressions.
                                                                                   ParameterExpression[] { exprParam });

                    // Call the *Fetch* function
                    var args = new object[] { currentQueryable, exprLambda };
                    currentQueryable = (IQueryable)fetchMethodInfo.Invoke(null, args) as IQueryable;

                    currentType = propType;
                    isFirstFetch = false;
                }
            }

            return currentQueryable;
        }
开发者ID:Vintharas,项目名称:Breeze,代码行数:94,代码来源:NHEagerFetch.cs


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