예제 #1
0
        public string GenerateQueryStatement(Type queryType)
        {
            if (!TypeUtils.IsBaseEntityQuery(queryType))
            {
                throw new ArgumentException("not a valid query type", "queryType");
            }
            Type baseType = queryType.BaseType;

            while (!baseType.IsGenericType)
            {
                baseType = baseType.BaseType;
            }
            var modelType = baseType.GetGenericArguments()[0];

            if (!TypeUtils.IsBaseEntity(modelType))
            {
                throw new ArgumentException("generic type is not a valid model type", "queryType");
            }

            var queryProperties = queryType.GetProperties();
            var modelProperties = modelType.GetProperties();
            var builder         = new StringBuilder();

            builder.AppendLine("#region override DoQuery <auto-generated-code>");
            builder.AppendLineFormat("public override IQueryable<{0}> {2}(IQueryable<{0}> {1})", modelType.Name, SourceParamName, QueryFuncName);
            builder.AppendLine("{");
            foreach (var queryProperty in queryProperties)
            {
                var context = new AnalyzeContext()
                {
                    QueryProperty   = queryProperty,
                    ModelType       = modelType,
                    SourceParamName = SourceParamName,
                    QueryParamName  = "this"
                };
                for (var index = 0; index < Analyzers.Length; index++)
                {
                    var analyzer      = Analyzers[index];
                    var modelProperty = analyzer.FindAttachedModelProperty(queryProperty, modelProperties);
                    if (modelProperty == null)
                    {
                        continue;
                    }
                    context.ModelProperty = modelProperty;
                    var statment = analyzer.ParseStatement(context);
                    queues[index].Add(statment);
                }
            }
            for (var index = 0; index < Analyzers.Length; index++)
            {
                builder.Append(string.Join("", queues[index]));
            }
            builder.Append(new PaginationAnalyzer().ParseStatement(modelProperties, SourceParamName));
            builder.AppendLineFormat("return {0};", SourceParamName);
            builder.AppendLine("}");
            builder.AppendLine("#endregion");
            return(builder.ToString());
        }
예제 #2
0
		public string GenerateQueryStatement(Type queryType)
		{
			if (!TypeUtils.IsBaseEntityQuery(queryType))
			{
				throw new ArgumentException("not a valid query type", "queryType");
			}
			Type baseType = queryType.BaseType;
			while (!baseType.IsGenericType)
			{
				baseType = baseType.BaseType;
			}
			var modelType = baseType.GetGenericArguments()[0];
			if (!TypeUtils.IsBaseEntity(modelType))
			{
				throw new ArgumentException("generic type is not a valid model type", "queryType");
			}

			var queryProperties = queryType.GetProperties();
			var modelProperties = modelType.GetProperties();
			var builder = new StringBuilder();
			builder.AppendLine("#region override DoQuery <auto-generated-code>");
			builder.AppendLineFormat("public override IQueryable<{0}> {2}(IQueryable<{0}> {1})", modelType.Name, SourceParamName, QueryFuncName);
			builder.AppendLine("{");
			foreach (var queryProperty in queryProperties)
			{
				var context = new AnalyzeContext()
					{
						QueryProperty = queryProperty,
						ModelType = modelType,
						SourceParamName = SourceParamName,
						QueryParamName = "this"
					};
				for (var index = 0; index < Analyzers.Length; index++)
				{
					var analyzer = Analyzers[index];
					var modelProperty = analyzer.FindAttachedModelProperty(queryProperty, modelProperties);
					if (modelProperty == null) continue;
					context.ModelProperty = modelProperty;
					var statment = analyzer.ParseStatement(context);
					queues[index].Add(statment);
				}
			}
			for (var index = 0; index < Analyzers.Length; index++)
			{
				builder.Append(string.Join("", queues[index]));
			}
			builder.Append(new PaginationAnalyzer().ParseStatement(modelProperties, SourceParamName));
			builder.AppendLineFormat("return {0};", SourceParamName);
			builder.AppendLine("}");
			builder.AppendLine("#endregion");
			return builder.ToString();
		}