Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When combining .Include and .Select in a linq query the result will be all rows in the table #3192

Closed
arildboifot opened this issue May 13, 2024 · 0 comments

Comments

@arildboifot
Copy link

Given a query like this, expecting 0 rows, it actually returns all rows.:

        var teams = new Dictionary<Guid, Team>();        
        var ids = Array.Empty<Guid>();
        var tp = await _session
           .Query<TeamPlayer>()
           .Include(x => x.TeamId, teams)
           .Where(x => x.Id.IsOneOf(ids) && x.IsAdministrator == true)
           .Select(x => x.PlayerId)
           .ToListAsync();

Generated sql with .Select

drop table if exists mt_temp_id_list1;
create temp table mt_temp_id_list1 as (
    select d.id, d.data, d.mt_version, d.tenant_id, d.mt_deleted, d.mt_deleted_at, d.player_id, d.team_id, d.pending_invitation, d.is_administrator
    from public.mt_doc_teamplayers as d
    where (d.mt_deleted = False and d.tenant_id = $1 and d.id = ANY($2) and d.is_administrator = $3)
);
  : *DEFAULT*
  :
  : True
 select d.id, d.data, d.mt_version, d.tenant_id, d.mt_deleted, d.mt_deleted_at
 from public.mt_doc_team as d
 where (d.mt_deleted = False and d.tenant_id = $1 and d.id in (select d.team_id from mt_temp_id_list1 as d));
  : *DEFAULT*

 select d.player_id from public.mt_doc_teamplayers as d

Generated sql without .Select

-- Query without .Select(x => x.PlayerId)
drop table if exists mt_temp_id_list1;
create temp table mt_temp_id_list1 as (
    select d.id, d.data, d.mt_version, d.tenant_id, d.mt_deleted, d.mt_deleted_at, d.player_id, d.team_id, d.pending_invitation, d.is_administrator
    from public.mt_doc_teamplayers as d
    where (d.mt_deleted = False and d.tenant_id = $1 and d.id = ANY($2) and d.is_administrator = $3)
);
  : *DEFAULT*
  :
  : True
 select d.id, d.data, d.mt_version, d.tenant_id, d.mt_deleted, d.mt_deleted_at
 from public.mt_doc_team as d
 where (d.mt_deleted = False and d.tenant_id = $1 and d.id in (select d.team_id from mt_temp_id_list1 as d));
  : *DEFAULT*
 select d.id, d.data, d.mt_version, d.tenant_id, d.mt_deleted, d.mt_deleted_at, d.player_id, d.team_id, d.pending_invitation, d.is_administrator from mt_temp_id_list1 as d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant