-
Notifications
You must be signed in to change notification settings - Fork 928
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix casting unsigned numeric types for Linq provider (#2447)
Fix #2445
- Loading branch information
Showing
4 changed files
with
386 additions
and
57 deletions.
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
src/NHibernate.Test/Async/NHSpecificTest/GH2445/Fixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System.Linq; | ||
using NHibernate.Cfg; | ||
using NHibernate.Cfg.MappingSchema; | ||
using NHibernate.Dialect; | ||
using NHibernate.Mapping.ByCode; | ||
using NHibernate.Test.NHSpecificTest.GH2445; | ||
using NUnit.Framework; | ||
using NHibernate.Linq; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2446 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class FixtureAsync : TestCaseMappingByCode | ||
{ | ||
protected override void Configure(Configuration configuration) | ||
{ | ||
configuration.SetProperty(Environment.Hbm2ddlKeyWords, "auto-quote"); | ||
} | ||
|
||
protected override bool AppliesTo(Dialect.Dialect dialect) | ||
{ | ||
return dialect is MySQLDialect || dialect is SQLiteDialect; | ||
} | ||
|
||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.Class<UnsignedEntity>(m => | ||
{ | ||
m.Id(c => c.Id, id => | ||
{ | ||
id.Generator(Generators.Native); | ||
}); | ||
m.Property(o => o.Short, o => o.NotNullable(true)); | ||
m.Property(o => o.Integer, o => o.NotNullable(true)); | ||
m.Property(o => o.Long, o => o.NotNullable(true)); | ||
m.Property(o => o.NullableNumber); | ||
m.Property(o => o.ShortNumber, o => o.NotNullable(true)); | ||
m.Property(o => o.NullableShortNumber); | ||
m.Property(o => o.LargeNumber, o => o.NotNullable(true)); | ||
m.Property(o => o.NullableLargeNumber); | ||
}); | ||
|
||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
protected override void OnSetUp() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
var entity = new UnsignedEntity() | ||
{ | ||
Short = 123, | ||
Integer = 12345, | ||
Long = 123456789, | ||
LargeNumber = 123456789, | ||
NullableLargeNumber = null, | ||
NullableNumber = null, | ||
ShortNumber = 123, | ||
NullableShortNumber = null | ||
}; | ||
session.Save(entity); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
session.CreateQuery("delete from UnsignedEntity").ExecuteUpdate(); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TestUIntAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
var number = 10; | ||
await (session.Query<UnsignedEntity>().Where(o => o.Id == (uint) number).ToListAsync()); | ||
await (session.Query<UnsignedEntity>().Where(o => o.Id == (uint) o.Integer).ToListAsync()); | ||
await (session.Query<UnsignedEntity>().Where(o => o.Id > number).ToListAsync()); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TestNullableUIntAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
var number = 10; | ||
await (session.Query<UnsignedEntity>().Where(o => o.NullableNumber == (uint?) number).ToListAsync()); | ||
await (session.Query<UnsignedEntity>().Where(o => o.NullableNumber == (uint?) o.Integer).ToListAsync()); | ||
await (session.Query<UnsignedEntity>().Where(o => o.NullableNumber > number).ToListAsync()); | ||
} | ||
} | ||
|
||
|
||
[Test] | ||
public async Task TestUShortAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
short number = 10; | ||
await (session.Query<UnsignedEntity>().Where(o => o.ShortNumber == (ushort) number).ToListAsync()); | ||
await (session.Query<UnsignedEntity>().Where(o => o.ShortNumber == (ushort) o.Short).ToListAsync()); | ||
await (session.Query<UnsignedEntity>().Where(o => o.ShortNumber > number).ToListAsync()); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TestNullableUShortAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
short number = 10; | ||
await (session.Query<UnsignedEntity>().Where(o => o.NullableShortNumber == (ushort?) number).ToListAsync()); | ||
await (session.Query<UnsignedEntity>().Where(o => o.NullableShortNumber == (ushort?) o.Short).ToListAsync()); | ||
await (session.Query<UnsignedEntity>().Where(o => o.NullableShortNumber > number).ToListAsync()); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TestULongAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
long number = 10; | ||
await (session.Query<UnsignedEntity>().Where(o => o.LargeNumber == (ulong) number).ToListAsync()); | ||
await (session.Query<UnsignedEntity>().Where(o => o.LargeNumber == (ulong) o.Long).ToListAsync()); | ||
await (session.Query<UnsignedEntity>().Where(o => o.LargeNumber > (ulong) number).ToListAsync()); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TestNullableULongAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
long number = 10; | ||
await (session.Query<UnsignedEntity>().Where(o => o.NullableLargeNumber == (ulong?) number).ToListAsync()); | ||
await (session.Query<UnsignedEntity>().Where(o => o.NullableLargeNumber == (ulong?) o.Long).ToListAsync()); | ||
await (session.Query<UnsignedEntity>().Where(o => o.NullableLargeNumber > (ulong?) number).ToListAsync()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
using System.Linq; | ||
using NHibernate.Cfg; | ||
using NHibernate.Cfg.MappingSchema; | ||
using NHibernate.Dialect; | ||
using NHibernate.Mapping.ByCode; | ||
using NHibernate.Test.NHSpecificTest.GH2445; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2446 | ||
{ | ||
[TestFixture] | ||
public class Fixture : TestCaseMappingByCode | ||
{ | ||
protected override void Configure(Configuration configuration) | ||
{ | ||
configuration.SetProperty(Environment.Hbm2ddlKeyWords, "auto-quote"); | ||
} | ||
|
||
protected override bool AppliesTo(Dialect.Dialect dialect) | ||
{ | ||
return dialect is MySQLDialect || dialect is SQLiteDialect; | ||
} | ||
|
||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.Class<UnsignedEntity>(m => | ||
{ | ||
m.Id(c => c.Id, id => | ||
{ | ||
id.Generator(Generators.Native); | ||
}); | ||
m.Property(o => o.Short, o => o.NotNullable(true)); | ||
m.Property(o => o.Integer, o => o.NotNullable(true)); | ||
m.Property(o => o.Long, o => o.NotNullable(true)); | ||
m.Property(o => o.NullableNumber); | ||
m.Property(o => o.ShortNumber, o => o.NotNullable(true)); | ||
m.Property(o => o.NullableShortNumber); | ||
m.Property(o => o.LargeNumber, o => o.NotNullable(true)); | ||
m.Property(o => o.NullableLargeNumber); | ||
}); | ||
|
||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
protected override void OnSetUp() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
var entity = new UnsignedEntity() | ||
{ | ||
Short = 123, | ||
Integer = 12345, | ||
Long = 123456789, | ||
LargeNumber = 123456789, | ||
NullableLargeNumber = null, | ||
NullableNumber = null, | ||
ShortNumber = 123, | ||
NullableShortNumber = null | ||
}; | ||
session.Save(entity); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
session.CreateQuery("delete from UnsignedEntity").ExecuteUpdate(); | ||
tx.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestUInt() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
var number = 10; | ||
session.Query<UnsignedEntity>().Where(o => o.Id == (uint) number).ToList(); | ||
session.Query<UnsignedEntity>().Where(o => o.Id == (uint) o.Integer).ToList(); | ||
session.Query<UnsignedEntity>().Where(o => o.Id > number).ToList(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestNullableUInt() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
var number = 10; | ||
session.Query<UnsignedEntity>().Where(o => o.NullableNumber == (uint?) number).ToList(); | ||
session.Query<UnsignedEntity>().Where(o => o.NullableNumber == (uint?) o.Integer).ToList(); | ||
session.Query<UnsignedEntity>().Where(o => o.NullableNumber > number).ToList(); | ||
} | ||
} | ||
|
||
|
||
[Test] | ||
public void TestUShort() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
short number = 10; | ||
session.Query<UnsignedEntity>().Where(o => o.ShortNumber == (ushort) number).ToList(); | ||
session.Query<UnsignedEntity>().Where(o => o.ShortNumber == (ushort) o.Short).ToList(); | ||
session.Query<UnsignedEntity>().Where(o => o.ShortNumber > number).ToList(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestNullableUShort() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
short number = 10; | ||
session.Query<UnsignedEntity>().Where(o => o.NullableShortNumber == (ushort?) number).ToList(); | ||
session.Query<UnsignedEntity>().Where(o => o.NullableShortNumber == (ushort?) o.Short).ToList(); | ||
session.Query<UnsignedEntity>().Where(o => o.NullableShortNumber > number).ToList(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestULong() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
long number = 10; | ||
session.Query<UnsignedEntity>().Where(o => o.LargeNumber == (ulong) number).ToList(); | ||
session.Query<UnsignedEntity>().Where(o => o.LargeNumber == (ulong) o.Long).ToList(); | ||
session.Query<UnsignedEntity>().Where(o => o.LargeNumber > (ulong) number).ToList(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestNullableULong() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
long number = 10; | ||
session.Query<UnsignedEntity>().Where(o => o.NullableLargeNumber == (ulong?) number).ToList(); | ||
session.Query<UnsignedEntity>().Where(o => o.NullableLargeNumber == (ulong?) o.Long).ToList(); | ||
session.Query<UnsignedEntity>().Where(o => o.NullableLargeNumber > (ulong?) number).ToList(); | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/NHibernate.Test/NHSpecificTest/GH2445/UnsignedEntity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace NHibernate.Test.NHSpecificTest.GH2445 | ||
{ | ||
public class UnsignedEntity | ||
{ | ||
public virtual uint Id { get; set; } | ||
|
||
public virtual short Short { get; set; } | ||
|
||
public virtual int Integer { get; set; } | ||
|
||
public virtual long Long { get; set; } | ||
|
||
public virtual uint? NullableNumber { get; set; } | ||
|
||
public virtual ushort ShortNumber { get; set; } | ||
|
||
public virtual ushort? NullableShortNumber { get; set; } | ||
|
||
public virtual ulong LargeNumber { get; set; } | ||
|
||
public virtual ulong? NullableLargeNumber { get; set; } | ||
} | ||
} |
Oops, something went wrong.