コード例 #1
0
        public IEnumerable <T> Select <T>(DataAspect aspect, ClassFilter filter, ClassSort sort, int pageSize, int pageOrdinal)
        {
            using (IDbConnection conn = _dialect.CreateConnection(_ConnectionString))
            {
                conn.Open();
                try
                {
                    IEnumerable <IDataRecord> records = _dialect.CreateSelect(aspect, filter, sort, pageSize, pageOrdinal).ExecuteQuery(conn);
                    if (pageSize > 0 && pageOrdinal >= 0)
                    {
                        if (!_dialect.CanOffsetRecords)
                        {
                            if (!_dialect.CanLimitRecords)
                            {
                                records = new Collections.EnumerablePager <IDataRecord>(records, pageSize, pageOrdinal);
                            }
                            else
                            {
                                records = new Collections.EnumerableOffset <IDataRecord>(records, pageSize * pageOrdinal);
                            }
                        }
                        else if (!_dialect.CanLimitRecords)
                        {
                            records = new Collections.EnumerableLimit <IDataRecord>(records, pageSize);
                        }
                    }

                    using (IEnumerator <IDataRecord> e = records.GetEnumerator())
                    {
                        if (e.MoveNext())
                        {
                            bool initializable = typeof(Initializable).IsAssignableFrom(aspect.DataType);
                            int  count         = e.Current.FieldCount;

                            do
                            {
                                T entity = (T)aspect.NewInstance();
                                for (int i = 0; i < count; i++)
                                {
                                    if (!e.Current.IsDBNull(i))
                                    {
                                        aspect[i].SetValue(entity, e.Current.GetValue(i));
                                    }
                                }
                                if (initializable)
                                {
                                    ((Initializable)entity).Initialize();
                                }
                                yield return(entity);
                            } while (e.MoveNext());
                        }
                    }
                }
                finally
                {
                    conn.Close();
                }
            }
        }
コード例 #2
0
 public virtual void AppendSort(StringBuilder builder, DataAspect aspect, ClassSort sort)
 {
     if (sort is ClassSortNode)
     {
         AppendSortNodes(builder, aspect, (ClassSortNode)sort);
     }
     else if (sort is ClassSortTerm)
     {
         AppendSortTerm(builder, aspect, (ClassSortTerm)sort);
     }
     else if (sort is ClassSortExpression)
     {
         AppendSortExpression(builder, aspect, (ClassSortExpression)sort);
     }
     else
     {
         throw new ArgumentException("Unknown sort type " + sort.GetType(), "sort");
     }
 }
コード例 #3
0
        public override DatabaseCommand CreateSelect(DataAspect aspect, ClassFilter filter, ClassSort sort, int pageSize, int pageOrdinal)
        {
            StringBuilder builder = new StringBuilder(255);
            int count = aspect.Count;

            builder.Append("SELECT ");
            if (pageSize > 0 && pageOrdinal >= 0)
            {
                builder.Append("TOP ");
                builder.Append((pageOrdinal + 1) * pageSize);
                builder.Append(' ');
            }

            AppendName(builder, aspect[0].StoredName);
            for (int i = 1; i < count; i++)
            {
                builder.Append(", ");
                AppendName(builder, aspect[i].StoredName);
            }
            builder.Append(" FROM ");
            AppendName(builder, aspect.StoredName);
            if (filter != null)
            {
                builder.Append(" WHERE ");
                AppendFilter(builder, aspect, filter);
            }
            if (sort != null)
            {
                builder.Append(" ORDER BY ");
                AppendSort(builder, aspect, sort);
            }
            return new DatabaseCommand(
                CommandType.Text,
                builder.ToString(),
                null);
        }
コード例 #4
0
        public override DatabaseCommand CreateSelect(DataAspect aspect, ClassFilter filter, ClassSort sort, int pageSize, int pageOrdinal)
        {
            StringBuilder builder = new StringBuilder(255);
            int           count   = aspect.Count;

            builder.Append("SELECT ");
            if (pageSize > 0 && pageOrdinal >= 0)
            {
                builder.Append("TOP ");
                builder.Append((pageOrdinal + 1) * pageSize);
                builder.Append(' ');
            }

            AppendName(builder, aspect[0].StoredName);
            for (int i = 1; i < count; i++)
            {
                builder.Append(", ");
                AppendName(builder, aspect[i].StoredName);
            }
            builder.Append(" FROM ");
            AppendName(builder, aspect.StoredName);
            if (filter != null)
            {
                builder.Append(" WHERE ");
                AppendFilter(builder, aspect, filter);
            }
            if (sort != null)
            {
                builder.Append(" ORDER BY ");
                AppendSort(builder, aspect, sort);
            }
            return(new DatabaseCommand(
                       CommandType.Text,
                       builder.ToString(),
                       null));
        }
コード例 #5
0
ファイル: AnsiDialect.cs プロジェクト: EixoX/Jetfuel-CSharp
        public virtual DatabaseCommand CreateSelectMember(DataAspect aspect, int ordinal, ClassFilter filter, ClassSort sort, int pageSize, int pageOrdinal)
        {
            StringBuilder builder = new StringBuilder(255);
            int count = aspect.Count;

            builder.Append("SELECT ");
            AppendName(builder, aspect[ordinal].StoredName);
            builder.Append(" FROM ");
            AppendName(builder, aspect.StoredName);
            if (filter != null)
            {
                builder.Append(" WHERE ");
                AppendFilter(builder, aspect, filter);
            }
            if (sort != null)
            {
                builder.Append(" ORDER BY ");
                AppendSort(builder, aspect, sort);
            }
            return new DatabaseCommand(
                CommandType.Text,
                builder.ToString(),
                null);
        }
コード例 #6
0
ファイル: AnsiDialect.cs プロジェクト: EixoX/Jetfuel-CSharp
 public virtual void AppendSort(StringBuilder builder, DataAspect aspect, ClassSort sort)
 {
     if (sort is ClassSortNode)
         AppendSortNodes(builder, aspect, (ClassSortNode)sort);
     else if (sort is ClassSortTerm)
         AppendSortTerm(builder, aspect, (ClassSortTerm)sort);
     else if (sort is ClassSortExpression)
         AppendSortExpression(builder, aspect, (ClassSortExpression)sort);
     else
         throw new ArgumentException("Unknown sort type " + sort.GetType(), "sort");
 }
コード例 #7
0
        public virtual DatabaseCommand CreateSelectMember(DataAspect aspect, int ordinal, ClassFilter filter, ClassSort sort, int pageSize, int pageOrdinal)
        {
            StringBuilder builder = new StringBuilder(255);
            int           count   = aspect.Count;

            builder.Append("SELECT ");
            AppendName(builder, aspect[ordinal].StoredName);
            builder.Append(" FROM ");
            AppendName(builder, aspect.StoredName);
            if (filter != null)
            {
                builder.Append(" WHERE ");
                AppendFilter(builder, aspect, filter);
            }
            if (sort != null)
            {
                builder.Append(" ORDER BY ");
                AppendSort(builder, aspect, sort);
            }
            return(new DatabaseCommand(
                       CommandType.Text,
                       builder.ToString(),
                       null));
        }
コード例 #8
0
 public ClassSortNode(ClassSort sort)
 {
     this._Term   = sort;
     this._Aspect = sort.Aspect;
 }
コード例 #9
0
 public ClassSortExpression(ClassSort sort)
 {
     this._First = new ClassSortNode(sort);
     this._Last  = this._First;
 }
コード例 #10
0
        public IEnumerable <object> SelectMember(DataAspect aspect, int ordinal, ClassFilter filter, ClassSort sort, int pageSize, int pageOrdinal)
        {
            using (IDbConnection conn = _dialect.CreateConnection(_ConnectionString))
            {
                conn.Open();
                try
                {
                    IEnumerable <IDataRecord> records = _dialect.CreateSelectMember(aspect, ordinal, filter, sort, pageSize, pageOrdinal).ExecuteQuery(conn);
                    if (pageSize > 0 && pageOrdinal >= 0)
                    {
                        if (!_dialect.CanOffsetRecords)
                        {
                            if (!_dialect.CanLimitRecords)
                            {
                                records = new Collections.EnumerablePager <IDataRecord>(records, pageSize, pageOrdinal);
                            }
                            else
                            {
                                records = new Collections.EnumerableOffset <IDataRecord>(records, pageSize * pageOrdinal);
                            }
                        }
                        else if (!_dialect.CanLimitRecords)
                        {
                            records = new Collections.EnumerableLimit <IDataRecord>(records, pageSize);
                        }
                    }

                    foreach (IDataRecord record in records)
                    {
                        yield return(record.GetValue(0));
                    }
                }
                finally
                {
                    conn.Close();
                }
            }
        }