0
I am using Nhibernate to make a query in sql in C#, but I have a doubt.
I have the following structure:
public class Pessoa {
   public long Id {get; set;}
   public string Nome {get; set;}
}
public class Usuario {
   public long Id { //Utiliza o id da pessoa }
   public Pessoa pessoa {get; set;}
}
What I would like to do is get a listing of the people who exist but are not linked to the user, that is, all the people who can become a user.
I am currently using the following code:
[HttpGet]
public IList<Pessoa> getPessoasSemUsuarios()
{
    var usuarios = Domain.Query(); //Lista de usuários
    var pessoas = pessoaDomain.Query(); //Lista de pessoas
    var pessoasSemUsuarios = new List<Pessoa>();
    pessoas.ToList().ForEach(pessoa =>
    {
        //Adiciona todas as pessoas que não são usuários.
        if (!usuarios.Any(x => x.Pessoa.Id == pessoa.Id))
            pessoasSemUsuarios .Add(pessoa);
    });
    return pessoasSemUsuarios ;
}
Note: I thought of something related to left Outer Join, but I’m not sure, any idea ?
my suggestion is to use left Join, and where bring null in that Join, will be the ones that can become a user.
– aa_sp