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(); } } }
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"); } }
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); }
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)); }
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); }
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"); }
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)); }
public ClassSortNode(ClassSort sort) { this._Term = sort; this._Aspect = sort.Aspect; }
public ClassSortExpression(ClassSort sort) { this._First = new ClassSortNode(sort); this._Last = this._First; }
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(); } } }