public async Task CastWithLengthAsync() { if (Regex.IsMatch(Dialect.GetCastTypeName(SqlTypeFactory.GetString(3)), @"^[^(]*$")) { Assert.Ignore($"Dialect {Dialect} does not seem to handle string length in cast"); } using (var s = OpenSession()) { try { var shortName = await(s .CreateCriteria <Student>() .SetProjection( Projections.Cast( TypeFactory.GetStringType(3), Projections.Property("Name"))) .UniqueResultAsync <string>()); Assert.That(shortName, Is.EqualTo("aye")); } catch (Exception e) { if (e.InnerException == null || !e.InnerException.Message.Contains("truncation")) { throw; } } } }
public async Task NullableIntOverflowAsync() { var hasCast = Dialect.GetCastTypeName(NHibernateUtil.Int32.SqlType) != Dialect.GetCastTypeName(NHibernateUtil.Int64.SqlType); using (var session = OpenSession()) using (session.BeginTransaction()) using (var sqlLog = new SqlLogSpy()) { var groups = await(session.Query <TestClass>() .GroupBy(i => 1) .Select(g => new { s = g.Sum(i => (long)i.NullableInt32Prop) }) .ToListAsync()); Assert.That(FindAllOccurrences(sqlLog.GetWholeLog(), "cast"), Is.EqualTo(hasCast ? 1 : 0)); Assert.That(groups, Has.Count.EqualTo(1)); Assert.That(groups[0].s, Is.EqualTo((long)int.MaxValue * 2)); } }