コード例 #1
0
ファイル: ExcelQueryExecutor.cs プロジェクト: westfin/Pad
        public IEnumerable <T> ExecuteCollection <T>(QueryModel queryModel)
        {
            this.visitor.VisitQueryModel(queryModel);
            var cmd = this.visitor.BuildSqlQuery();

            var projector = this.GetSelectProj <T>(queryModel);

            cmd.Connection = ExcelHelperClass.GetConnection(this.args);
            if (cmd.Connection.State == System.Data.ConnectionState.Closed)
            {
                cmd.Connection.Open();
            }

            cmd.Parameters.AddRange(this.visitor.Builder.Params.ToArray());

            var data         = cmd.ExecuteReader();
            var objData      = this.GetDataObj(queryModel, data);
            var resultObject = objData.Cast(projector);

            return(resultObject);
        }
コード例 #2
0
        protected override Expression VisitMemberExpression(MemberExpression expression)
        {
            var prop    = expression.Member as PropertyInfo;
            var columns = ExcelHelperClass.GetColumnNames(args);

            if (prop == null)
            {
                return(expression);
            }

            var columnNameProp = prop.GetCustomAttribute <ExcelColumnAttribute>();

            if (!columns.Contains(columnNameProp.ColumnName))
            {
                throw new MappingException(columnNameProp.ColumnName, this.args);
            }

            this.whereClause.Append($" {columnNameProp.ColumnName} ");

            return(expression);
        }
コード例 #3
0
ファイル: ExcelQueryExecutor.cs プロジェクト: westfin/Pad
        private IEnumerable <object> GetDataObj(QueryModel queryModel, IDataReader data)
        {
            var results = new List <object>();

            while (data.Read())
            {
                var obj     = Activator.CreateInstance(queryModel.MainFromClause.ItemType);
                var props   = obj.GetType().GetProperties();
                var columns = ExcelHelperClass.GetColumnNames(this.args);
                foreach (var prop in props)
                {
                    var columnNameProp = prop.GetCustomAttribute <ExcelColumnAttribute>();
                    if (!columns.Contains(columnNameProp.ColumnName))
                    {
                        throw new MappingException(columnNameProp.ColumnName, this.args);
                    }

                    prop.SetValue(obj, data[columnNameProp.ColumnName]);
                }

                results.Add(obj);
            }
            return(results);
        }