protected PaginatedList <T> ExecuteStoredProcedurePaginated <T>(string name, IDictionary <string, object> parameters, int start, int count) where T : new() { using (var reader = ExecuteStoredProcedureReader(name, parameters)) { if (reader.Read()) { var allCount = SqlTools.ReadInt32(reader, ALL_COUNT_FIELD); reader.NextResult(); var res = reader.ReadList <T>(); return(new PaginatedList <T>(res, start / count, count, allCount)); } return(new PaginatedList <T>(new List <T>(), start / count, count, 0)); } }
protected PaginatedList <T> ReadPaginatedResult <T>(DbQuery dbQuery, int start, int count, Func <DbDataReader, IList <T> > readAction) where T : new() { using (var reader = ExecuteReaderParametrized(dbQuery.Sql.ToString(), dbQuery.Parameters as Dictionary <string, object>)) { if (reader.Read()) { var allCount = SqlTools.ReadInt32(reader, ALL_COUNT_FIELD); reader.NextResult(); var res = readAction(reader); return(new PaginatedList <T>(res, start / count, count, allCount)); } return(new PaginatedList <T>(new List <T>(), start / count, count, 0)); } }
protected int SimpleInsert <T>(T obj, bool returnInsertedEntityId = false) { var q = Orm.Orm.SimpleInsert(obj, returnInsertedEntityId); var insertedEntityId = -1; if (returnInsertedEntityId) { using (var reader = ExecuteReaderParametrized(q.Sql.ToString(), q.Parameters)) { if (reader.Read()) { insertedEntityId = SqlTools.ReadInt32(reader, "insertedEntityId"); } } } else { ExecuteNonQueryParametrized(q.Sql.ToString(), q.Parameters); } return(insertedEntityId); }
protected bool Exists <T>(QueryCondition conditions) where T : new() { var q = Orm.Orm.CountSelect <T>(conditions, ALL_COUNT_FIELD); return(Read(q, reader => reader.Read() && SqlTools.ReadInt32(reader, ALL_COUNT_FIELD) > 0)); }
private int ReadCount(DbQuery query) { return(Read(query, reader => reader.Read() ? SqlTools.ReadInt32(reader, ALL_COUNT_FIELD) : 0)); }
protected bool Exists(DbQuery query, string resName = ALL_COUNT_FIELD) { var q = Orm.Orm.CountSelect(query, resName); return(Read(q, reader => reader.Read() && SqlTools.ReadInt32(reader, resName) > 0)); }