View Model receiving Null values

2

After a query in the DB, my query returns some null values in some attributes and the time to pass the values to the model:

ViewModel.Participantes.Add(new RelParticipantesInscritosAtividadeVM { 
  RA = p.RA.Value, Nome = p.Nome, Modulo = p.Modulo.Value 
});

I get this error message:

  

The null object must have a value

How do I get my model to get null values or replace null with a default value?

    
asked by anonymous 20.09.2017 / 14:05

1 answer

1

It would be nice for you to make clear which attributes can not receive null, but anyway, depending on the type of the attribute you can declare it as nullable something like:

public int? RA { get;set; }

or make a treatment to receive a value if the return of the bank is null:

RA = p.RA.Value == null ? "valor default" : p.RA.Value;
    
20.09.2017 / 14:35