public object Query(Type elementType, Expression expression) { var converter = new SqlConverter(elementType, connectionType); if (TableNames.ContainsKey(elementType)) { converter.TableName = TableNames[elementType]; } var sql = converter.ExpressionConvert(expression); OpenConnecion(); object result = null; switch (converter.SelectMode) { case SelectMode.Count: result = connection.QueryFirstOrDefault <int>(sql, converter.DynamicParameters); break; case SelectMode.Any: result = connection.Query(sql, converter.DynamicParameters).Any(); break; case SelectMode.Select: case SelectMode.All: result = connection.QueryFirstOrDefault(elementType, sql, converter.DynamicParameters); break; default: break; } return(result); }
public IEnumerable <T> Query <T>(Expression expression) { var elementType = GetElementType(expression); var converter = new SqlConverter(elementType, connectionType); if (TableNames.ContainsKey(elementType)) { converter.TableName = TableNames[elementType]; } var sql = converter.ExpressionConvert(expression); OpenConnecion(); return(connection.Query <T>(sql, converter.DynamicParameters)); }