예제 #1
0
        public SqlCommandDescription Generate(MethodInfo methodInfo, object[] arguments)
        {
            var context = SqlCommandGenerateContext.Create()
                          .SetMethod(methodInfo)
                          .Build();

            string cacheKey = $"SqlCOmmandDescription_{context.ToString()}";
            SqlCommandDescription description = cache.GetOrCreate <SqlCommandDescription>(cacheKey, key =>
            {
                if (context.HasAnyQueryAttribute)
                {
                    return(GetDescriptionByQuery(context));
                }
                else
                {
                    return(GetSqlCommandDescriptionWithourParameterFilled(context));
                }
            });

            if (arguments != null && arguments.Length != 0)
            {
                ParameterLookupContext lookupContet
                    = new ParameterLookupContext
                      (
                          this,
                          description,
                          methodInfo,
                          arguments
                      );
                this.parameterLookupFactory.Lookup(lookupContet);
            }
            return(description);
        }
예제 #2
0
 public ParameterLookupContext(ISqlCommandGenerator sqlCommandGenerator, SqlCommandDescription description, MethodInfo methodInfo, object[] values)
 {
     SqlCommandGenerator = sqlCommandGenerator;
     Description         = description;
     MethodInfo          = methodInfo;
     Values = values;
 }
예제 #3
0
        /// <summary>
        /// 根据 <see cref="QueryAttribute"/>  获取数据库执行信息
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private SqlCommandDescription GetDescriptionByQuery(SqlCommandGenerateContext context)
        {
            string querySelector = NpiConfig.QuerySelector;
            IEnumerable <SqlAttribute> queryAttributes = context.QueryAttributes.Where(x => x.Selector == querySelector);

            if (queryAttributes.Count() > 1)
            {
                throw new ApplicationException("匹配到多个 QueryAttribute");
            }

            SqlAttribute queryAttribute = queryAttributes.FirstOrDefault();

            SqlCommandDescription description = new SqlCommandDescription()
            {
                SqlCommand = queryAttribute.Sql,
                Mode       = queryAttribute.Mode
            };

            foreach (var ps in this.sqlParameterFinder.Find(queryAttribute.Sql))
            {
                description.AddParameter(new SqlParameterInfo(ps));
            }

            return(description);
        }