解决C#中Guid不能为空

C#中的GUID数据类型与数据库中的uniqueidentifier数据类型是对应的,但是C#中的GUID是不接受空值的,而数据库的uniqueidentifier却接受空值,所以在开发过程中可能会出现类似下图的这种报错信息,大意就是某字段为空,必须设置该字段为GUID的非空值。

那么如何解决这种问题呢,其实也比较简单,只需要在设定属性的时候在GUID后加个?就行了,这样在C#中GUID就可以接受空值,同样之前遇到过一个数据库时间和C#时间格式不匹配的问题,同样加?也可以解决,具体还能怎么耍就需要后续慢慢接触了。

    public class AdminAccountEntity : ModifiedEntity
    {
        public string AccountName { get; set; }
        public string PassWord { get; set; }
        public string Name { get; set; }
        public string Tel { get; set; }
        public string IdentityCard { get; set; }
        public Guid? AdminClassifyID { get; set; }
    }
THE END