Skip to content

Commit 5d6b354

Browse files
Apply suggestions from code review
Co-authored-by: Frédéric Delaporte <[email protected]>
1 parent 6e8911c commit 5d6b354

File tree

9 files changed

+13
-17
lines changed

9 files changed

+13
-17
lines changed

src/NHibernate.Test/TypesTest/GenericTypeFixtureBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ public virtual void CanQueryProperties()
224224
var value = property.Compile()(testValue);
225225
var where = Expression.Lambda<Func<TestEntity, bool>>(Expression.Equal(body.Replace(property.Parameters[0], prop), Expression.Constant(value)), param);
226226
TestEntity entity = null;
227-
Assert.DoesNotThrow(() => entity = session.Query<TestEntity>().FirstOrDefault(where), "Unable to query property " + member.Member.Name);
227+
Assert.That(() => entity = session.Query<TestEntity>().FirstOrDefault(where), Throws.Nothing,
228+
"Unable to query property " + member.Member.Name);
228229
Assert.That(entity, Is.Not.Null, "Unable to query property " + member.Member.Name);
229230
}
230231
}

src/NHibernate.Test/TypesTest/TimeOnlyAsTicksTypeFixture.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace NHibernate.Test.TypesTest
1111
{
12-
1312
[TestFixture(false)]
1413
[TestFixture(true)]
1514
public class TimeOnlyAsTicksTypeFixture : AbstractTimeOnlyTypeWithScaleFixture<TimeOnlyAsTicksType>

src/NHibernate/Type/AbstractDateOnlyType.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public override object Get(DbDataReader rs, int index, ISessionImplementor sessi
3737
}
3838
catch (Exception ex) when (ex is not FormatException)
3939
{
40-
throw new FormatException(string.Format("Input string '{0}' was not in the correct format.", rs[index]), ex);
40+
throw new FormatException(string.Format("Input '{0}' was not convertible to DateOnly.", rs[index]), ex);
4141
}
4242
}
4343

@@ -50,7 +50,7 @@ public override object Get(DbDataReader rs, int index, ISessionImplementor sessi
5050
/// <inheritdoc />
5151
public override void Set(DbCommand st, object value, int index, ISessionImplementor session)
5252
{
53-
st.Parameters[index].Value = GetParameterValueToSet((DateOnly) value,session);
53+
st.Parameters[index].Value = GetParameterValueToSet((DateOnly) value, session);
5454
}
5555

5656
/// <summary>
@@ -82,7 +82,6 @@ public override bool IsEqual(object x, object y)
8282
/// <inheritdoc />
8383
public override string ToLoggableString(object value, ISessionFactoryImplementor factory) =>
8484
value == null ? null : ((DateOnly) value).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
85-
8685
}
8786
}
8887
#endif

src/NHibernate/Type/AbstractTimeOnlyType.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ protected AbstractTimeOnlyType(byte? fractionalSecondsPrecision, SqlType sqlType
3838
}
3939
}
4040

41-
4241
public override string Name => GetType().Name.EndsWith("Type", StringComparison.Ordinal)
4342
? GetType().Name[..^4]
4443
: GetType().Name;
@@ -50,7 +49,7 @@ protected AbstractTimeOnlyType(byte? fractionalSecondsPrecision, SqlType sqlType
5049
public override object DefaultValue => TimeOnly.MinValue;
5150

5251
/// <summary>
53-
/// Truncate (floor) fractional seconds beyond declared precision.
52+
/// Truncate (floor) fractional seconds according to the declared precision.
5453
/// Override to change behavior (e.g., implement rounding).
5554
/// </summary>
5655
protected virtual TimeOnly AdjustTimeOnly(TimeOnly timeOnly)
@@ -89,7 +88,7 @@ public override object Get(DbDataReader rs, int index, ISessionImplementor sessi
8988
}
9089
catch (Exception ex) when (ex is not FormatException)
9190
{
92-
throw new FormatException(string.Format("Input string '{0}' was not in the correct format.", rs[index]), ex);
91+
throw new FormatException(string.Format("Input '{0}' was not convertible to TimeOnly.", rs[index]), ex);
9392
}
9493
}
9594

src/NHibernate/Type/DateOnlyAsDateType.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ protected override DateOnly GetDateOnlyFromReader(DbDataReader rs, int index, IS
2828
protected override DateTime GetParameterValueToSet(DateOnly dateOnly, ISessionImplementor session) =>
2929
dateOnly.ToDateTime(TimeOnly.MinValue);
3030

31-
3231
/// <inheritdoc />
3332
public override string ObjectToSQLString(object value, Dialect.Dialect dialect) =>
34-
"'" + ((DateOnly) value).ToString("yyyy-MM-dd") + "'";
33+
dialect.ToStringLiteral(((DateOnly) value).ToString("yyyy-MM-dd"), SqlTypeFactory.GetAnsiString(50));
3534
}
3635
}
3736
#endif

src/NHibernate/Type/TimeOnlyAsDateTimeType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void IParameterizedType.SetParameterValues(IDictionary<string, string> parameter
6161
}
6262

6363
public override string ObjectToSQLString(object value, Dialect.Dialect dialect) =>
64-
"'" + GetDateTimeFromTimeOnly(AdjustTimeOnly((TimeOnly) value)).ToString(_sqlFormat) + "'";
64+
dialect.ToStringLiteral(GetDateTimeFromTimeOnly(AdjustTimeOnly((TimeOnly) value)).ToString(_sqlFormat), SqlTypeFactory.GetAnsiString(50));
6565
}
6666
}
6767
#endif

src/NHibernate/Type/TimeOnlyAsTicksType.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
namespace NHibernate.Type
1616
{
17-
1817
/// <summary>
1918
/// Maps a <see cref="System.TimeOnly" /> property to a <see cref="DbType.Int64" /> column.
2019
/// The value persisted is the Ticks property of the TimeOnly value.
@@ -48,7 +47,7 @@ public TimeOnlyAsTicksType(byte fractionalSecondsPrecision) : base(fractionalSec
4847
protected override long GetParameterValueToSet(TimeOnly timeOnly, ISessionImplementor session) => timeOnly.Ticks;
4948

5049
public override string ObjectToSQLString(object value, Dialect.Dialect dialect) =>
51-
AdjustTimeOnly((TimeOnly) value).Ticks.ToString();
50+
dialect.ToStringLiteral(AdjustTimeOnly((TimeOnly) value).Ticks.ToString(), SqlTypeFactory.GetAnsiString(50));
5251
}
5352
}
5453
#endif

src/NHibernate/Type/TimeOnlyAsTimeType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected override TimeOnly GetTimeOnlyFromReader(DbDataReader rs, int index, IS
4848
{
4949
if (rs.GetFieldType(index) == typeof(TimeSpan)) //For those dialects where DbType.Time means TimeSpan.
5050
{
51-
return new TimeOnly(((TimeSpan)rs[index]).Ticks);
51+
return new TimeOnly(((TimeSpan) rs[index]).Ticks);
5252
}
5353

5454
var dbValue = rs.GetDateTime(index);
@@ -72,7 +72,7 @@ void IParameterizedType.SetParameterValues(IDictionary<string, string> parameter
7272
}
7373

7474
public override string ObjectToSQLString(object value, Dialect.Dialect dialect) =>
75-
"'" + (AdjustTimeOnly((TimeOnly) value)).ToString(_sqlFormat) + "'";
75+
dialect.ToStringLiteral(AdjustTimeOnly((TimeOnly) value).ToString(_sqlFormat), SqlTypeFactory.GetAnsiString(50));
7676
}
7777
}
7878
#endif

src/NHibernate/Type/TypeFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ private static void RegisterDefaultNetTypes()
342342

343343
// object needs to have both class and serializable setup before it can
344344
// be created.
345-
RegisterType(typeof (Object), NHibernateUtil.Object, new[] {"object"});
346-
345+
RegisterType(typeof (Object), NHibernateUtil.Object, new[] {"object"});
347346

348347
#if NET6_0_OR_GREATER
349348
RegisterType(typeof(DateOnly), NHibernateUtil.DateOnlyAsDate, new[] { "dateonly", "dateonlyasdate" });
@@ -936,6 +935,7 @@ public static NullableType GetTimeType(byte fractionalSecondsPrecision)
936935
var key = GetKeyForLengthOrScaleBased(NHibernateUtil.Time.Name, fractionalSecondsPrecision);
937936
return (NullableType)typeByTypeOfName.GetOrAdd(key, k => new TimeType(SqlTypeFactory.GetTime(fractionalSecondsPrecision)));
938937
}
938+
939939
#if NET6_0_OR_GREATER
940940
/// <summary>
941941
/// Gets a <see cref="TimeOnlyAsDateTimeType" /> with desired fractional seconds precision.

0 commit comments

Comments
 (0)