Entity Framework | Double property that allows null

Asked

Viewed 439 times

5

My property allows values double and values null. In the SQL Server Database it is set to decimal(18, 2).

But when seventh some value (ex: 5.00), makes the mistake below.

Error:

The 'Rating' Property on 'Occurrence' could not be set to a 'System.Decimal' value. You must set this Property to a non-null value of type 'System.Double'.

Model:

public class Ocorrencia
{
    [Key]
    public int id { get; set; }
    public double? Avaliacao { get; set; }
}

How it should stay to function properly?

2 answers

6


You can cast for double

ocorrencia.Avaliacao = (double)5.00;
  • Would not be ocorrencia.Avaliacao = (double)5.00;?

  • I made this slip and already corrected rsrsrs

3

Maybe you’re not forcing the notation to double:

ocorrencia.Avaliacao = 5.00D;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.