Uniqueidentifier in SQL becomes lowercase in C #

I have a column (uniqueidentifier) ​​in SQL that stores guid. I see this in uppercase. But when data is returned using SP code in C #, it becomes more strict.

I use an entity structure in data access. What could be the reason and can I avoid this conversion?

+6
source share
3 answers

If you use the Entity Framework, uniqueidentifier data is converted to Guid.

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

If you need consistency in the application, you can use one format when you get a string from Guid.

Check Guid.ToString (String) Method for Available Formats

There may be a place where you get guid as a string from the database, so this will be infinite uppercase. (check the stored procedures "Views, etc.")

To avoid this problem, you must make sure that you return the uniqueidentifier as it is, do not convert to varchar, and also switch to one multi-line format when converting to a string.

For other operations, such as comparison, etc. You can use the guid operators.

+6
source

The unique identifier is not case sensitive. Have a problem?

+2
source

I suspect that SQL Server stores the unique identifier as a 128-bit integer and then converts it to hex for display. As Alexander says, it doesn’t matter if this hexadecimal value is displayed in upper or lower case, as they represent the same thing.

If that matters to your application, you can convert it to uppercase in C # without any problems.

+2
source

Source: https://habr.com/ru/post/946582/


All Articles