Error: System.NullReferenceException: 'Object reference not set to an instance of an object.'

-1

I have the Agenda object class, according to the information below:

namespace Teach.Negocio.Models
{
    [Table(name: "Agendas")]
    public class Agenda
    {
        public long Id { get; set; }
        public virtual Aluno Aluno { get; set; }
        public String Endereco { get; set; }
        public DateTime HoraInicial { get; set; }
        public DateTime HoraFinal { get; set; }
        public TimeSpan TotalHoras { get { return HoraFinal - HoraInicial; } set { } }
        public decimal Valor { get { return Convert.ToDecimal(this.TotalHoras.Hours + (this.TotalHoras.Minutes/60)) * this.Aluno.ValorHoraAula; } set { } }
        public String Observacoes { get; set; }
        public virtual Professor Professor { get; set; }
        public virtual Fatura Fatura { get; set; }


        public Agenda()
        {
        }
         public TimeSpan HorasCalculo()
        {
            this.TotalHoras = HoraFinal - HoraInicial;
            return TotalHoras;
        }

        [NotMapped]
        public String NomeAluno
        {
            get
            {
                return Aluno.Nome;
            }
        }

        [NotMapped]
        public DateTime DataAgendamento
        {
            get
            {
                return HoraInicial.Date;
            }
        }
    }
}

When you log in to the system and register for a new "Scheduling" according to the information stated above, the same thing happens normally. However, running the program a second time, it pops the error below:

  

System.NullReferenceException: 'Object reference not set to an instance of an object.'

Can anyone help me?

    
asked by anonymous 24.06.2018 / 03:06

1 answer

0

Change the current Value getter to:

public decimal Valor { get { return Convert.ToDecimal(this.HorasCalculo().Hours + (this.HorasCalculo().Minutes/60)) * this.Aluno.ValorHoraAula; } set { } }
    
05.07.2018 / 18:20