public override TResult Execute <TResult>(SqlConnection connection) { if (typeof(TResult) != typeof(IEnumerable <TProjected>)) { throw new NotSupportedException(); } var targetQueryable = this.queryable; if (this.predicate != null) { targetQueryable = new WhereQueryable <TProjected, TMapped>(this.queryable, this.predicate); } var query = targetQueryable.Parse(); query.OrderBy.Clear(); var sql = string.Format( "SELECT TOP 1 * FROM ({0}) {1}_{2}", query, query.Name, Guid.NewGuid().ToString().Replace("-", "")); connection.SendQueryToProfiler(sql); return((TResult)(object)new SqlEnumerable <TProjected, TMapped>(connection, sql)); }
public override TResult Execute <TResult>(SqlConnection connection) { if (typeof(TResult) != typeof(int)) { throw new NotSupportedException(); } var targetQueryable = this.Queryable; if (this.Predicate != null) { targetQueryable = new WhereQueryable <TProjected, TMapped>(this.Queryable, this.Predicate); } var query = targetQueryable.Parse(); query.OrderBy.Clear(); query.Select.Clear(); query.Select.Append("1 Nothing"); var sql = string.Format("SELECT COUNT(1) FROM ( {0} ) {1}", query, query.Name); connection.SendQueryToProfiler(sql); object scalar; using (var command = new SqlCommand(sql, connection)) { scalar = command.ExecuteScalar(); } return((TResult)scalar); }