Problem with Nullable Column
-
06 Mart 2012 Salı 17:29
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
Tüm Yanıtlar
-
06 Mart 2012 Salı 17:48
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- Yanıt Olarak İşaretleyen Deise Vicentin 06 Mart 2012 Salı 17:48
-
07 Mart 2012 Çarşamba 02:22Moderatör
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