Ejemplo n.º 1
0
        public static bool TryParsePath(Expression expression, out string path)
        {
            path = (string)null;
            Expression           expression1          = expression.RemoveConvert();
            MemberExpression     memberExpression     = expression1 as MemberExpression;
            MethodCallExpression methodCallExpression = expression1 as MethodCallExpression;

            if (memberExpression != null)
            {
                string name = memberExpression.Member.Name;
                string path1;
                if (!DbHelpers.TryParsePath(memberExpression.Expression, out path1))
                {
                    return(false);
                }
                path = path1 == null ? name : path1 + "." + name;
            }
            else if (methodCallExpression != null)
            {
                string path1;
                if (methodCallExpression.Method.Name == "Select" && methodCallExpression.Arguments.Count == 2 && (DbHelpers.TryParsePath(methodCallExpression.Arguments[0], out path1) && path1 != null))
                {
                    LambdaExpression lambdaExpression = methodCallExpression.Arguments[1] as LambdaExpression;
                    string           path2;
                    if (lambdaExpression != null && DbHelpers.TryParsePath(lambdaExpression.Body, out path2) && path2 != null)
                    {
                        path = path1 + "." + path2;
                        return(true);
                    }
                }
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static string ParsePropertySelector <TEntity, TProperty>(
            Expression <Func <TEntity, TProperty> > property,
            string methodName,
            string paramName)
        {
            string path;

            if (!DbHelpers.TryParsePath(property.Body, out path) || path == null)
            {
                throw new ArgumentException(Strings.DbEntityEntry_BadPropertyExpression((object)methodName, (object)typeof(TEntity).Name), paramName);
            }
            return(path);
        }