Skip to content

Commit 3120d08

Browse files
committed
Avoid casting when propertyName is provided; Restored switch
1 parent 9874a47 commit 3120d08

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/NHibernate/Criterion/CriterionUtil.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,8 @@ public static TypedValue GetTypedValue(
168168
string propertyName,
169169
object value)
170170
{
171-
var propertyProjection = projection as IPropertyProjection;
172-
if (projection == null || propertyProjection != null)
173-
{
174-
var pn = propertyProjection != null ? propertyProjection.PropertyName : propertyName;
175-
return criteriaQuery.GetTypedValue(criteria, pn, value);
176-
}
171+
if (propertyName != null || (propertyName = (projection as IPropertyProjection)?.PropertyName) != null)
172+
return criteriaQuery.GetTypedValue(criteria, propertyName, value);
177173

178174
return new TypedValue(NHibernateUtil.GuessType(value), value);
179175
}

src/NHibernate/Criterion/PropertyExpression.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteri
7575
var otherColumnNames =
7676
CriterionUtil.GetColumnNamesAsSqlStringParts(_rhsPropertyName, _rhsProjection, criteriaQuery, criteria);
7777

78-
if (columnNames.Length == 0)
79-
return SqlString.Empty;
80-
if (columnNames.Length == 1)
81-
return new SqlString(columnNames[0], Op, otherColumnNames[0]);
78+
switch (columnNames.Length)
79+
{
80+
case 1:
81+
return new SqlString(columnNames[0], Op, otherColumnNames[0]);
82+
case 0:
83+
return SqlString.Empty;
84+
}
8285

8386
var sb = new SqlStringBuilder();
8487
sb.Add(StringHelper.OpenParen);

0 commit comments

Comments
 (0)