I have column(uniqueidentifier) in SQL which stored guid. I see that its in upper case. But when the data is returned through SP to C# code it becomes lower case
I am using entity framework in data access. What could be the reason and can i avoid this conversion?
The globally unique identifier (GUID) data type in SQL Server is represented by the uniqueidentifier data type, which stores a 16-byte binary value. A GUID is a binary number, and its main use is as an identifier that must be unique in a network that has many computers at many sites.
The following example converts a uniqueidentifier value to a char data type. DECLARE @myid uniqueidentifier = NEWID(); SELECT CONVERT(CHAR(255), @myid) AS 'char'; The following example demonstrates the truncation of data when the value is too long for the data type being converted to.
All Caps SQL Commands For readability, all SQL commands should be written in uppercase letters. This allows the reader to identify the keywords in the SQL statement and easily determine what the query is executing.
A table with a UNIQUEIDENTIFIER column. The primary key in this table is of type UNIQUEIDENTIFIER . The values are generated by the NEWID function. With this setup, the primary key values are autogenerated, just like IDENTITY.
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..
I suspect that SQL Server stores a uniqueidentifier as a 128-bit integer and then converts it to hexadecimal for display. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With