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 @   Merakia  阅读(30)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
点击右上角即可分享
微信分享提示