|
8 | 8 | using NHibernate.Persister.Entity;
|
9 | 9 | using NHibernate.Type;
|
10 | 10 | using Remotion.Linq.Clauses.Expressions;
|
| 11 | +using NHibernate.Util; |
11 | 12 |
|
12 | 13 | namespace NHibernate.Linq.Visitors
|
13 | 14 | {
|
@@ -172,7 +173,7 @@ private bool CanBeEvaluatedInHql(MemberExpression memberExpression)
|
172 | 173 | }
|
173 | 174 |
|
174 | 175 | // Check whether the member is mapped
|
175 |
| - var entityName = TryGetEntityName(memberExpression, out var memberPath); |
| 176 | + var entityName = ExpressionsHelper.TryGetEntityName(_parameters.SessionFactory, memberExpression, out var memberPath); |
176 | 177 | if (entityName == null)
|
177 | 178 | {
|
178 | 179 | return false; // Not mapped
|
@@ -207,9 +208,9 @@ private bool CanBeEvaluatedInHql(BinaryExpression binaryExpression)
|
207 | 208 | var canBeEvaluated = CanBeEvaluatedInHql(binaryExpression.Left) &
|
208 | 209 | CanBeEvaluatedInHql(binaryExpression.Right);
|
209 | 210 |
|
210 |
| - // Subtract datetimes on the client side as its result varies when executed on the server side. |
| 211 | + // Subtract datetimes on the client side as the result varies when executed on the server side. |
211 | 212 | // In Sql Server when using datetime2 subtract is not possbile.
|
212 |
| - // In Oracle a number is returned that represents the difference bewteen the two in days. |
| 213 | + // In Oracle a number is returned that represents the difference between the two in days. |
213 | 214 | if (new[]
|
214 | 215 | {
|
215 | 216 | ExpressionType.Subtract,
|
@@ -316,41 +317,6 @@ private void VisitMemberBindings(IEnumerable<MemberBinding> bindings)
|
316 | 317 | }
|
317 | 318 | }
|
318 | 319 |
|
319 |
| - private string TryGetEntityName(MemberExpression memberExpression, out string memberPath) |
320 |
| - { |
321 |
| - System.Type entityType; |
322 |
| - memberPath = memberExpression.Member.Name; |
323 |
| - // When having components we need to go though them in order to find the entity |
324 |
| - while (memberExpression.Expression is MemberExpression subMemberExpression) |
325 |
| - { |
326 |
| - // In some cases we can encounter a property representing the entity e.g. [_0].Customer.CustomerId |
327 |
| - if (subMemberExpression.NodeType == ExpressionType.MemberAccess) |
328 |
| - { |
329 |
| - var entityName = _parameters.SessionFactory.TryGetGuessEntityName(memberExpression.Member.ReflectedType); |
330 |
| - if (entityName != null) |
331 |
| - { |
332 |
| - return entityName; |
333 |
| - } |
334 |
| - } |
335 |
| - |
336 |
| - memberPath = $"{subMemberExpression.Member.Name}.{memberPath}"; // Build a path that can be used to get the property form the entity metadata |
337 |
| - memberExpression = subMemberExpression; |
338 |
| - } |
339 |
| - |
340 |
| - // Try to get the actual entity type from the query source if possbile as member can be declared |
341 |
| - // in a base type |
342 |
| - if (memberExpression.Expression is QuerySourceReferenceExpression querySourceReferenceExpression) |
343 |
| - { |
344 |
| - entityType = querySourceReferenceExpression.Type; |
345 |
| - } |
346 |
| - else |
347 |
| - { |
348 |
| - entityType = memberExpression.Member.ReflectedType; |
349 |
| - } |
350 |
| - |
351 |
| - return _parameters.SessionFactory.TryGetGuessEntityName(entityType); |
352 |
| - } |
353 |
| - |
354 | 320 | private static bool ContainsAnyOfTypes(IEnumerable<Expression> expressions, params System.Type[] types)
|
355 | 321 | {
|
356 | 322 | return expressions.Any(o => types.Contains(o.Type));
|
|
0 commit comments