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); }