Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong comparison of GUID (aka UniqueIdentifier) values #129

Open
kind-serge opened this issue Aug 27, 2018 · 4 comments
Open

Wrong comparison of GUID (aka UniqueIdentifier) values #129

kind-serge opened this issue Aug 27, 2018 · 4 comments
Assignees

Comments

@kind-serge
Copy link

kind-serge commented Aug 27, 2018

SQL Server has a slightly different way of comparing GUID values as opposed to .NET implementation, so operators like Less and Greater return unexpected results with the Effort.
.NET framework compares first 4 bytes (uint), then next 2 bytes (ushort), then next 2 bytes (ushort), then rest of 8 bytes one by one.
And here is an example of how SQL Server does comparison of GUIDs: https://stackoverflow.com/questions/6945878/how-is-a-guid-actually-stored-and-sorted-compared-in-sql-server#answer-49300469

@JonathanMagnan
Copy link
Member

Hello @TYROTOXIN ,

Thank for letting us known.

We are currently looking at all open issues to clean/make them, so we will eventually soon check this one as well.

Best Regards,

Jonathan


Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper PlusLinqToSql Plus

Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval FunctionSQL Eval Function

@JonathanMagnan JonathanMagnan self-assigned this Aug 28, 2018
@JonathanMagnan
Copy link
Member

Hello @TYROTOXIN ,

We started to investigate this issue. However, we are not sure how you use the Less or Greater comparator since that's not supported in C# by default.

Could you provide a code example of how you use it when the provider is SQL Server? Perhaps that will help us to better understand to find a solution.

Best Regards,

Jonathan

@kind-serge
Copy link
Author

Yeah, it's very simple. Consider such case:

class Record
{
  public Guid Id { get; set; }
}
class SampleDbContext
{
  DbSet<Record> Records { get; set; }
}

...

// Example 1: Filtering
Guid minId = ...;
var records = dbContext.Records.Where(r => r.Id.CompareTo(minId) >= 0).ToList();

....

// Example 2: Ordering
var records = dbContext.Records.OrderBy(r => r.Id).ToList();

@JonathanMagnan
Copy link
Member

Hello @TYROTOXIN ,

Thank for the additional information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants