Database default value is not inserted while create record by entity framework

前端 未结 3 1745
庸人自扰
庸人自扰 2021-02-15 17:33

I have a LoginRecord table in sqlserver 2008 with the following column structure-

LoginId      - int, identity
UserId       - int
LoginDateTime- Allow nulls fals         


        
3条回答
  •  深忆病人
    2021-02-15 17:38

    In addition to changing the EDMX file as suggested by Vishwaram Maharaj, you should make the definition of the table match between EF and the DB. The table description of "LoginDateTime- Allow nulls false" is itself false. The field clearly allows NULLs if NULLs are being inserted. Alter the column to not allow NULL if it truly shouldn't have NULL values in it:

    ALTER TABLE LoginRecords ALTER COLUMN LoginDateTime DATETIME NOT NULL;
    

提交回复
热议问题