guid当主键记录

转换string和GUID

`static string str = "21140D4D-9CB3-41C1-99DC-30B4BCBE1989"; private static Guid DefaultGuid = new Guid(str);`

报错 : One of the identified items was in an invalid format.
在使用了方法2,以后发现存入的guid再数据库中是乱码。删掉以后就正常了. 我修改额profile中guid的方法 从guid.NewGuid改成 new guid就好了

1.实体继承IHasDeletionTime的时候,默认的IsDeleted字段代码中是Bool类型,MySql存储的是tinyint(1),此时就会报错,解决方法:连接字符串中加入TreatTinyAsBoolean=true;
2.实体使用Guid当主键,MySql存储的是char(36),此时查询可能会报错(One of the identified items was in an invalid format.),解决方法:连接字符串加入OldGuids=true;
3.实体使用Guid当主键,批量操作时可能会报错,此时实体创建时,请使用IGuidGenerator 主动给Guid赋值

本随便为自己做的笔记。原文章 :https://www.cnblogs.com/getmn/p/14890545.html 

posted @ 2023-12-07 10:33  Merakia  阅读(41)  评论(0)    收藏  举报