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

 

 

 

posted @ 2019-01-07 15:22  ChuckLu  阅读(394)  评论(0编辑  收藏  举报