Skip to content

Commit 0f5e585

Browse files
committed
Improves LocalCollectionKeyTypeExtractor
If part of BinaryExpression is already KeyExpression then we can get KeyType form it
1 parent 2254d13 commit 0f5e585

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

Orm/Xtensive.Orm/Orm/Linq/LocalCollectionKeyTypeExtractor.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2013 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2013-2020 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Kulakov
55
// Created: 2013.12.30
66

@@ -10,6 +10,7 @@
1010
using System.Linq.Expressions;
1111
using System.Text;
1212
using Xtensive.Core;
13+
using Xtensive.Orm.Linq.Expressions;
1314

1415
namespace Xtensive.Orm.Linq
1516
{
@@ -18,28 +19,34 @@ internal static class LocalCollectionKeyTypeExtractor
1819
public static Type Extract(BinaryExpression expression)
1920
{
2021
ArgumentValidator.EnsureArgumentNotNull(expression, "expression");
22+
if (expression.Right.StripMarkers() is KeyExpression key) {
23+
return key.EntityType.UnderlyingType;
24+
}
25+
2126
var expr = VisitBinaryExpession(expression);
22-
if (expr.Type.IsSubclassOf(typeof (Entity)))
27+
if (expr.Type.IsSubclassOf(typeof(Entity))) {
2328
return expr.Type;
29+
}
30+
2431
throw new NotSupportedException(string.Format(Strings.ExCurrentTypeXIsNotSupported, expr.Type));
2532
}
2633

2734
private static Expression VisitBinaryExpession(BinaryExpression binaryExpression)
2835
{
29-
var memberExpression = binaryExpression.Right as MemberExpression;
30-
if (memberExpression==null)
31-
throw new InvalidOperationException(string.Format(Strings.ExCantConvertXToY, binaryExpression.Type, typeof (MemberExpression)));
36+
if (!(binaryExpression.Right is MemberExpression memberExpression)) {
37+
throw new InvalidOperationException(string.Format(Strings.ExCantConvertXToY, binaryExpression.Type, typeof(MemberExpression)));
38+
}
3239
return VisitMemberExpression(memberExpression);
3340
}
3441

3542
private static Expression VisitMemberExpression(MemberExpression memberExpression)
3643
{
37-
var parameter = memberExpression.Expression as ParameterExpression;
38-
if (parameter!=null)
44+
if (memberExpression.Expression is ParameterExpression parameter) {
3945
return parameter;
40-
var member = memberExpression.Expression as MemberExpression;
41-
if (member!=null)
46+
}
47+
if (memberExpression.Expression is MemberExpression member) {
4248
return member;
49+
}
4350
throw new NotSupportedException(string.Format(Strings.ExCurrentTypeOfExpressionXIsNotSupported, memberExpression.Expression.Type));
4451
}
4552
}

0 commit comments

Comments
 (0)