DapperLib / Dapper

Dapper - a simple object mapper for .Net
https://www.learndapper.com/
Other
17.48k stars 3.67k 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 #2041

Closed rafaelfernandesdorazio closed 7 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

mgravell commented 7 months ago

I am using the latest version of Dommel

Maybe ask Dommel?