-
Notifications
You must be signed in to change notification settings - Fork 936
Fix Guid.ToString() #1856
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
Fix Guid.ToString() #1856
Changes from 17 commits
168ea4b
b25d520
5b0a70a
c68b0ae
cfb2de0
4657d59
1427a00
8a3ceab
17540ed
a700fc6
4e97cce
ce8f896
f798727
d066e72
a0dcade
f274dc4
309e0a3
cd7d155
46d68b4
3b6b1a0
ed9835b
f8cc863
94c0f54
11d3b12
1768076
db44444
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3426 | ||
{ | ||
public class Entity | ||
{ | ||
public virtual Guid Id { get; set; } | ||
public virtual string Name { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Linq; | ||
using NHibernate.Cfg.MappingSchema; | ||
using NHibernate.Dialect; | ||
using NHibernate.Mapping.ByCode; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3426 | ||
{ | ||
[TestFixture] | ||
public class Fixture : TestCaseMappingByCode | ||
{ | ||
|
||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.Class<Entity>(rc => | ||
{ | ||
rc.Id(x => x.Id); | ||
rc.Property(x => x.Name); | ||
}); | ||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
private static readonly string _id = "9FF2D288-56E6-F349-9CFC-48902132D65B"; | ||
|
||
protected override void OnSetUp() | ||
{ | ||
using (var session = OpenSession()) | ||
{ | ||
session.Save(new Entity { Id = Guid.Parse(_id), Name = "Name 1" }); | ||
|
||
session.Flush(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
{ | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
session.Delete("from System.Object"); | ||
|
||
session.Flush(); | ||
transaction.Commit(); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public void SelectGuidToString() | ||
{ | ||
using (var session = OpenSession()) | ||
{ | ||
var list = session.Query<Entity>() | ||
.Select(x => new { Id = x.Id.ToString() }) | ||
.ToList(); | ||
|
||
Assert.AreEqual(_id.ToUpper(), list[0].Id.ToUpper()); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System.Data; | ||
using NHibernate.Dialect.Function; | ||
fredericDelaporte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
using NHibernate.SqlCommand; | ||
|
||
namespace NHibernate.Dialect | ||
|
@@ -22,6 +23,8 @@ protected override void RegisterCastTypes() { | |
RegisterCastType(DbType.Double, "DECIMAL(19,5)"); | ||
RegisterCastType(DbType.Single, "DECIMAL(19,5)"); | ||
RegisterCastType(DbType.Guid, "BINARY(16)"); | ||
|
||
RegisterFunction("strguid", new SQLFunctionTemplate(NHibernateUtil.String, "concat(hex(reverse(substr(?1, 1, 4))), '-', hex(reverse(substring(?1, 5, 2))), '-', hex(reverse(substr(?1, 7, 2))), '-', hex(substr(?1, 9, 2)), '-', hex(substr(?1, 11)))")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So works both under Linux and Windows. But endianness is processor dependent. I guess both run under x86/amd64 systems. Anyone able of testing this with a PowerPC maybe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should not have problems with endianness because on these 2 systems Guids are stored as What we, potentially, can do is to add a runtime check into a function generator. We also need to have a test which checks a server generated Guids. |
||
} | ||
|
||
//Reference 5.x | ||
|
Uh oh!
There was an error while loading. Please reload this page.