uniqueidentifier in SQL becomes lower case in c#

 https://stackoverflow.com/questions/16938151/uniqueidentifier-in-sql-becomes-lower-case-in-c-sharp

If you using Entity Framework, uniqueidentifier data will convert to Guid.

The value of this Guid, represented as a series of lowercase hexadecimal digits in the specified format.

If you need consistency in your application you can use one format when you get string out of Guid.

Check Guid.ToString Method (String) for available formats

There can be a place where you get guid as string from database so that will be infinity upper case. ( check stored procedures Views etc..)

To avoid this issue you have to make sure that return uniqueidentifier as it is, don't convert to varchar and also follow one stranded format when converting to string.

For other operations like comparing etc..You can use Guid operators.. 

 

 
In C#, Guid.NewGuid().ToString() returns string in lower case; and in SQL server, SELECT NEWID() returns string in upper case. Why is that?

 

如果要把字符串的guid转换为字节数组的话,可以先进行parse,然后再tobytearray

https://docs.microsoft.com/en-us/dotnet/api/system.guid.parse?view=netframework-4.7.2

https://docs.microsoft.com/en-us/dotnet/api/system.guid.tobytearray?view=netframework-4.7.2

 

guid的字节序问题

https://stackoverflow.com/questions/9195551/why-does-guid-tobytearray-order-the-bytes-the-way-it-does

 

 

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(397)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2016-01-07 VS2015中添加新建项,找不到ado .net entity datamodel的解决方法
2016-01-07 vs2015中安装EntityFramework
点击右上角即可分享
微信分享提示