GetElementType() 정적인 개인적인 메소드

static private GetElementType ( Type seqType ) : Type
seqType System.Type
리턴 System.Type
예제 #1
0
        public override object Execute(Expression expression)
        {
            try {
                Type   elementType  = TypeSystem.GetElementType(expression.Type);
                string methodName   = ((MethodCallExpression)expression).Method.Name;
                bool   isIQueryable = expression.Type.FullName.StartsWith("System.Linq.IQueryable");
                string queryString  = String.Format(this.Translate(expression), m_domainName);

                if (!OrderBy.IsNullOrBlank())
                {
                    string orderByField = (OrderBy.IndexOf(' ') != -1) ? OrderBy.Substring(0, OrderBy.IndexOf(' ')) : OrderBy;
                    // SimpleDB queries with an order clause must have the order field included as a predicate.
                    // If the select query does not contain the a predicate with the order field add it here.
                    if (!queryString.Contains(orderByField))
                    {
                        queryString += " and " + orderByField + " like '%'";
                    }
                    queryString += " order by " + OrderBy;
                }

                if (Count != Int32.MaxValue)
                {
                    queryString += " limit " + Count;
                }

                //logger.Debug(queryString);

                if (!queryString.IsNullOrBlank())
                {
                    //logger.Debug("SimpleDB select: " + queryString + ".");
                    SelectRequest request = new SelectRequest();
                    request.SelectExpression = queryString;
                    SelectResponse response = m_service.Select(request);
                    if (response.IsSetSelectResult())
                    {
                        if (elementType == typeof(Int32))
                        {
                            return(Convert.ToInt32(response.SelectResult.Item[0].Attribute[0].Value));
                        }
                        else
                        {
                            object result = Activator.CreateInstance(
                                typeof(SimpleDBObjectReader <>).MakeGenericType(elementType),
                                BindingFlags.Instance | BindingFlags.Public, null,
                                new object[] { response.SelectResult, m_setter },
                                null);

                            if (isIQueryable)
                            {
                                return(result);
                            }
                            else
                            {
                                IEnumerator enumerator = ((IEnumerable)result).GetEnumerator();
                                if (enumerator.MoveNext())
                                {
                                    return(enumerator.Current);
                                }
                                else
                                {
                                    return(null);
                                }
                            }
                        }
                    }
                    throw new ApplicationException("No results for SimpleDB query.");
                }
                else
                {
                    throw new ApplicationException("The expression translation by the SimpleDBQueryProvider resulted in an empty select string.");
                }
            }
            catch (Exception excp) {
                logger.Error("Exception SimpleDBQueryProvider Execute. " + expression.ToString() + ". " + excp.Message);
                throw;
            }
        }
예제 #2
0
        public override object Execute(Expression expression)
        {
            try {
                Type   elementType  = TypeSystem.GetElementType(expression.Type);
                string methodName   = ((MethodCallExpression)expression).Method.Name;
                bool   isIQueryable = (expression.Type.FullName.StartsWith("System.Linq.IQueryable") || expression.Type.FullName.StartsWith("System.Linq.IOrderedQueryable"));
                string queryString  = String.Format(this.Translate(expression), m_tableName);

                if (!OrderBy.IsNullOrBlank())
                {
                    queryString += " order by " + OrderBy;
                }

                if (Count != Int32.MaxValue)
                {
                    queryString += " limit " + Count;
                }

                if (Offset != 0)
                {
                    queryString += " offset " + Offset;
                }

                //logger.Debug(queryString);

                if (!queryString.IsNullOrBlank())
                {
                    using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Suppress))
                    {
                        using (IDbConnection connection = m_dbFactory.CreateConnection()) {
                            connection.ConnectionString = m_dbConnStr;
                            connection.Open();

                            if (elementType == typeof(Int32))
                            {
                                // This is a count.
                                IDbCommand command = connection.CreateCommand();
                                command.CommandText = queryString;
                                return(Convert.ToInt32(command.ExecuteScalar()));
                            }
                            else
                            {
                                //logger.Debug("SimpleDB select: " + queryString + ".");
                                IDbCommand command = connection.CreateCommand();
                                command.CommandText = queryString;
                                IDbDataAdapter adapter = m_dbFactory.CreateDataAdapter();
                                adapter.SelectCommand = command;
                                DataSet resultSet = new DataSet();
                                adapter.Fill(resultSet);

                                if (resultSet != null && resultSet.Tables[0] != null)
                                {
                                    object result = Activator.CreateInstance(
                                        typeof(SQLObjectReader <>).MakeGenericType(elementType),
                                        BindingFlags.Instance | BindingFlags.Public, null,
                                        new object[] { resultSet, m_setter },
                                        null);

                                    if (isIQueryable)
                                    {
                                        return(result);
                                    }
                                    else
                                    {
                                        IEnumerator enumerator = ((IEnumerable)result).GetEnumerator();
                                        if (enumerator.MoveNext())
                                        {
                                            return(enumerator.Current);
                                        }
                                        else
                                        {
                                            return(null);
                                        }
                                    }
                                }
                            }
                        }
                        throw new ApplicationException("No results for SQL query.");
                    }
                }
                else
                {
                    throw new ApplicationException("The expression translation by the SQLQueryProvider resulted in an empty select string.");
                }
            }
            catch (Exception excp) {
                logger.Error("Exception SQLQueryProvider Execute. " + expression.ToString() + ". " + excp.Message);
                throw;
            }
        }