Search code examples
c#-4.0fluent-nhibernatefluent-nhibernate-mapping

When GUID is retrieved using Fluent nhibernate, the string is converted to lowercase


I have a table, which has apikey and secretkey. Both are uniqueIdentifiers datatype in sql.

When I use Fluent NHibernate to retrieve the record, the other fields like Authorized domains have their text retrieved in what ever case is there in database.

But for Secret column, the text retrieved is lowercase. i.e. D28DCFE1-692E-4C0A-ADD8-DF9CF6A375FC => d28dcfe1-692e-4c0a-add8-df9cf6a375fc

This is causing me problems, because I have to uppercase and then send it to generate signature. Lower and uppercase cause different signatures.

The datamodel is:

public virtual string BrandId { get; set; }
public virtual Guid ApiKey { get; set; }
public virtual string SharedSecret { get; set; }
public virtual string ContactEmail { get; set; }

Now I dont want to purposely make it uppercase after retrieving, because what if a lowercase secretkey was shared with the apiusers....

Is there a config change I need to do for FNH. Or change in mapping? I researched, for this problem, but seems like no one encountered this issue.

Mapping:

Id(x => x.ApiKey);
Map(x => x.SharedSecret);
Map(x => x.BrandId);

Solution

  • Cause

    it's most probably a problem with how the sql server handles uniqueIdentifiers. The string you send it will be converted to bytes ignoring the case and when retrieving converted to lower case string.

    Proof

    Run a Select directly on the database and look at the results to verify this.

    Solution

    Change the datatype to a string type like varchar.