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


C# MemberExpression.StripForIncludeScanning方法代码示例

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


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

示例1: VisitMemberAccess

		protected override Expression VisitMemberAccess(MemberExpression memberExpression)
		{
			MemberExpression expression; 
			var visited = new List<MemberExpression>();
			var root = memberExpression.Expression.StripForIncludeScanning();
			var memberIsDataAccessObjectGatheringForProjection = false;

			// Don't perform implicit joins for RelatedDataAccessObject collections as those currently turn into N+1 queries
			if (this.nesting < 1 && (memberExpression.Type.GetSequenceElementType()?.IsDataAccessObjectType() ?? false))
			{
				return base.VisitMemberAccess(memberExpression);
			}
			
			if (memberExpression.Type.IsTypeRequiringJoin())
			{
				if (this.forProjection)
				{
					memberIsDataAccessObjectGatheringForProjection = true;

					expression = memberExpression.StripForIncludeScanning() as MemberExpression;
				}
				else
				{
					expression = memberExpression.Expression.StripForIncludeScanning() as MemberExpression;

					if (expression == null || !expression.Expression.StripForIncludeScanning().Type.IsTypeRequiringJoin())
					{
						return memberExpression;
					}
				}
			}
			else
			{
				if (memberExpression.Expression?.StripForIncludeScanning() == null)
				{
					return memberExpression;
				}

				var typeDescriptor = this.model.TypeDescriptorProvider.GetTypeDescriptor(memberExpression.Expression.StripForIncludeScanning().Type);

				if (typeDescriptor == null)
				{
					return Expression.MakeMemberAccess(this.Visit(memberExpression.Expression.StripForIncludeScanning()), memberExpression.Member);
				}

				var property = typeDescriptor.GetPropertyDescriptorByPropertyName(memberExpression.Member.Name);

				if (property.IsPrimaryKey && memberExpression.Expression.StripForIncludeScanning() is MemberExpression)
				{
					expression = ((MemberExpression)memberExpression.Expression.StripForIncludeScanning()).Expression.StripForIncludeScanning() as MemberExpression;
				}
				else
				{
					expression = memberExpression.Expression.StripForIncludeScanning() as MemberExpression;
				}
			}

			var currentExpression = expression.StripForIncludeScanning() as MemberExpression;

			while (currentExpression?.Member is PropertyInfo)
			{
				visited.Add(currentExpression);

				root = currentExpression.Expression.StripForIncludeScanning();

				currentExpression = root as MemberExpression;

				if (currentExpression == null)
				{
					root = this.GetExpression(root).StripForIncludeScanning();
					currentExpression = root as MemberExpression;
				}
			}

			var includedPathSkip = 0;

			var i = 0;

			foreach (var current in visited)
			{
				if (!current.Member.ReflectedType.IsTypeRequiringJoin()
					|| current == this.currentParent /* @see: Test_Select_Project_Related_Object_And_Include1 */)
				{
					includedPathSkip = visited.Count - i;
					
					break;
				}

				i++;
			}

			visited.Reverse();

			i = 0;
			currentExpression = expression;

			while (currentExpression?.Member is PropertyInfo)
			{
				var path = new PropertyPath(c => c.Name, visited.Select(c=> (PropertyInfo)c.Member).Take(visited.Count - i).ToArray());
				
//.........这里部分代码省略.........
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:101,代码来源:ReferencedRelatedObjectPropertyGatherer.cs


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