private IEnumerable <T> List(SQLCeVisitor <T> visitor) { var command = BuildCommand(visitor); var connectionString = ContentQuery.Repository.GetConnectionString(); List <T> list = new List <T>(); SqlCeConnection connection; using (var dataReader = SQLCeHelper.ExecuteReader(connectionString, command, out connection)) { try { while (dataReader.Read()) { T content = new T(); list.Add(dataReader.ToContent(content)); } } finally { dataReader.Close(); connection.Close(); } } return(list); }
private int Count(SQLCeVisitor <T> visitor) { IEnumerable <Parameter> parameters; var sql = BuildQuerySQL(visitor, out parameters); var connectionString = ContentQuery.Repository.GetConnectionString(); sql = string.Format("SELECT COUNT(Id) FROM ({0})T", sql); var command = BuildCommand(sql, parameters); return((int)SQLCeHelper.ExecuteScalar(connectionString, command)); }
private T LastOrDefault(SQLCeVisitor <T> visitor) { IEnumerable <Parameter> parameters; var sql = BuildQuerySQL(visitor, out parameters); var connectionString = ContentQuery.Repository.GetConnectionString(); string orderBy = "Id ASC"; if (visitor.OrderClauses != null && visitor.OrderClauses.Count > 0) { orderBy = ToReverseOrderString(visitor); } if (visitor.Skip != 0) { sql = string.Format("SELECT * FROM ({0})T ORDER BY {1} OFFSET {2} ROWS FETCH NEXT 1 ROWS ONLY", sql, orderBy, visitor.Skip); } else { sql = string.Format("SELECT TOP 1 * FROM ({0})T ORDER BY {1}", sql, orderBy); } var command = BuildCommand(sql, parameters); T content = null; SqlCeConnection connection; using (var dataReader = SQLCeHelper.ExecuteReader(connectionString, command, out connection)) { try { if (dataReader.Read()) { content = new T(); dataReader.ToContent(content); } } finally { dataReader.Close(); connection.Close(); } } return(content); }