TryResolveOptimizedIdentity() public method

public TryResolveOptimizedIdentity ( SqlEntityRefMemberExpression entityRefMemberExpression ) : Expression
entityRefMemberExpression Remotion.Linq.SqlBackend.SqlStatementModel.Unresolved.SqlEntityRefMemberExpression
return System.Linq.Expressions.Expression
示例#1
0
        private static KeyValuePair <string, object>[] TryResolvePropertyExpression(
            MappingResolverStub mappingResolver, Expression expression, object value)
        {
            var columnExpression = expression as SqlColumnExpression;

            if (columnExpression != null)
            {
                return new[] { new KeyValuePair <string, object> (columnExpression.ColumnName, value) }
            }
            ;

            var newExpression = expression as NewExpression;

            if (newExpression != null)
            {
                return
                    (newExpression.Arguments.SelectMany(
                         (a, i) =>
                {
                    var argumentMemberValue = value != null ? ((PropertyInfo)newExpression.Members[i]).GetValue(value, null) : null;
                    return TryResolvePropertyExpression(mappingResolver, a, argumentMemberValue);
                }).ToArray());
            }

            var namedExpression = expression as NamedExpression;

            if (namedExpression != null)
            {
                return(TryResolvePropertyExpression(mappingResolver, namedExpression.Expression, value));
            }

            var memberRefExpression = (SqlEntityRefMemberExpression)expression;
            var optimizedIdentity   = mappingResolver.TryResolveOptimizedIdentity(memberRefExpression);

            if (optimizedIdentity == null)
            {
                return(new KeyValuePair <string, object> [0]);
            }

            var idOfReferencedEntity = value != null?value.GetType().GetProperty("ID").GetValue(value, null) : null;

            return(TryResolvePropertyExpression(mappingResolver, optimizedIdentity, idOfReferencedEntity));
        }
    private static KeyValuePair<string, object>[] TryResolvePropertyExpression (
        MappingResolverStub mappingResolver, Expression expression, object value)
    {
      var columnExpression = expression as SqlColumnExpression;
      if (columnExpression != null)
        return new[] { new KeyValuePair<string, object> (columnExpression.ColumnName, value) };

      var newExpression = expression as NewExpression;
      if (newExpression != null)
      {
        return
            newExpression.Arguments.SelectMany (
            (a, i) =>
            {
              var argumentMemberValue = value != null ? ((PropertyInfo) newExpression.Members[i]).GetValue (value, null) : null;
              return TryResolvePropertyExpression (mappingResolver, a, argumentMemberValue);
            }).ToArray();
      }

      var namedExpression = expression as NamedExpression;
      if (namedExpression != null)
        return TryResolvePropertyExpression (mappingResolver, namedExpression.Expression, value);

      var memberRefExpression = (SqlEntityRefMemberExpression) expression;
      var optimizedIdentity = mappingResolver.TryResolveOptimizedIdentity (memberRefExpression);
      if (optimizedIdentity == null)
        return new KeyValuePair<string, object>[0];

      var idOfReferencedEntity = value != null ? value.GetType().GetProperty ("ID").GetValue (value, null) : null;
      return TryResolvePropertyExpression (mappingResolver, optimizedIdentity, idOfReferencedEntity);
    }