henkmollema / Dommel

CRUD operations with Dapper made simple.
MIT License
611 stars 99 forks source link

An error is occurring when executing Select - variable 'p' of type 'Escola.Entities.Aluno' referenced from scope '', but it is not defined #300

Closed rafaelfernandesdorazio closed 5 months ago

rafaelfernandesdorazio commented 7 months ago

    public class BaseEntity
    {
        [Key]
        public Guid Id { get; set; }
    }

    public class Classe : BaseEntity
    {
        public string Nome { get; set; } = string.Empty;
    }   

    public class Aluno : BaseEntity
    {
        public Guid ClasseId { get; set; }
        public string Nome { get; set; } = string.Empty;
        public string Cpf { get; set; } = string.Empty;
        public string Rg { get; set; } = string.Empty;
        public required DateTime DataNascimento { get; set; }
        public Classe Classe { get; set; } = new Classe();
    }

    public class Classe : BaseEntity
    {
        public string Nome { get; set; } = string.Empty;
    }

This query is giving an error

        public IEnumerable<Aluno> GetByClasseId(Guid classeId)
        {
            var result = _unitOfWork.Connection.Select<Aluno, Classe, Aluno>(p => p.Classe.Id == classeId, _unitOfWork.Transaction);

            return result;
        }

This query works

        public IEnumerable<Aluno> GetByClasseId(Guid classeId)
        {
            var result = _unitOfWork.Connection.Select<Aluno, Classe, Aluno>(p => p.ClasseId == classeId, _unitOfWork.Transaction);

            return result;
        }

When I use a Child Entity to make the query the error occurs

variable 'p' of type 'Escola.Entities.Aluno' referenced from scope '', but it is not defined

I am using the latest version of Dommel

henkmollema commented 5 months ago

Selecting on nested/child entities does indeed not work. This is expected behavior.