简体   繁体   English

SQL中的uniqueidentifier在c#中变为小写

[英]uniqueidentifier in SQL becomes lower case in c#

I have column(uniqueidentifier) in SQL which stored guid. 我在SQL中有列(uniqueidentifier)存储guid。 I see that its in upper case. 我看到它是大写的。 But when the data is returned through SP to C# code it becomes lower case 但是当数据通过SP返回到C#代码时,它变为小写

I am using entity framework in data access. 我在数据访问中使用实体框架。 What could be the reason and can i avoid this conversion? 可能是什么原因,我能避免这种转变吗?

If you using Entity Framework, uniqueidentifier data will convert to Guid. 如果您使用Entity Framework, uniqueidentifier数据将转换为Guid。

The value of this Guid, represented as a series of lowercase hexadecimal digits in the specified format. 此Guid的值,表示为指定格式的一系列小写十六进制数字。

If you need consistency in your application you can use one format when you get string out of Guid. 如果您的应用程序需要一致性,那么当您从Guid中获取字符串时,可以使用一种格式。

Check Guid.ToString Method (String) for available formats 检查Guid.ToString方法(字符串)以获取可用格式

There can be a place where you get guid as string from database so that will be infinity upper case. 可以有一个地方,你从数据库获取guid作为字符串,这将是无限大写。 ( 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. 要避免此问题,您必须确保按原样返回uniqueidentifier ,不转换为varchar,并在转换为字符串时遵循一种搁浅格式。

For other operations like comparing etc..You can use Guid operators.. 对于比较等其他操作。你可以使用Guid操作符..

I suspect that SQL Server stores a uniqueidentifier as a 128-bit integer and then converts it to hexadecimal for display. 我怀疑SQL Server将uniqueidentifier存储为128位整数,然后将其转换为十六进制以供显示。 As Alexander says, it doesn't matter whether it displays this hexadecimal value in upper-case or lower-case as they represent the same thing. 正如亚历山大所说,无论它是以大写还是小写显示这个十六进制值都没关系,因为它们代表相同的东西。

If it matters to your application, then you can convert it to upper-case in C# without a problem. 如果它对您的应用程序很重要,那么您可以在C#中将其转换为大写而不会出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM