none
Problem with Nullable Column RRS feed

  • Question

  • I am using the Entity Framework 4.1.

    I have this Entity:

        [Table("MENSAGEM")]
        public class Mensagem : IEntityModel
        {
            [Key]
            [Column("PAME_CD_MENSAGEM")]
            public int Codigo { get; set; }
    
            [Column("USUA_CD_USUARIO"), ForeignKey("Usuario")]
            public int CodigoUsuario { get; set; }
    
            public Usuario Usuario { get; set; }
    
            [Column("PAME_DT_LEITURA")] 
            public DateTime DataLeitura { get; set; }
    
        }
    

    When I run my application the message is showing in screen:

    The 'DataLeitura' property on 'Mensagem' could not be set to a 'null' value. You must set this property to a non-null value of type 'DateTime'.

    But in my database the column is nullable.

    Somebody know what is this?

    Thanks!!!


    Deise Vicentin
    "Eu não procuro saber as respostas, procuro compreender as perguntas." Confúcio

    Tuesday, March 6, 2012 5:29 PM

Answers

  • I discovered the problem.

    I put Nullable in the attribute:

    [Column("PAME_DT_LEITURA")] 
    public Nullable<DateTime> DataLeitura { get; set; }

    Thanks! :D


    Deise Vicentin
    "Eu não procuro saber as respostas, procuro compreender as perguntas." Confúcio

    Tuesday, March 6, 2012 5:48 PM

All replies

  • I discovered the problem.

    I put Nullable in the attribute:

    [Column("PAME_DT_LEITURA")] 
    public Nullable<DateTime> DataLeitura { get; set; }

    Thanks! :D


    Deise Vicentin
    "Eu não procuro saber as respostas, procuro compreender as perguntas." Confúcio

    Tuesday, March 6, 2012 5:48 PM
  • Hi Deise Vicentin,

    Welcome to MSDN Forum.

    I'm glad to hear that you have solved the issue and thanks for sharing the experience. With your help, the forum will be better and better.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, March 7, 2012 2:22 AM
    Moderator