public int Count(IEdmCollectionType collectionType, ODataQueryOptions queryOptions) { var entityType = collectionType.ElementType.Definition as EdmEntityType; int count = 0; if (entityType != null) { using (var connection = new SqlConnection(_connectionString)) { var countSql = _sqlQueryBuilder.ToCountSql(queryOptions); var commandDefinition = new CommandDefinition(countSql.Query, countSql.Parameters, commandType: CommandType.Text); count = connection.Query <int>(commandDefinition).Single(); } } return(count); }