public void Delete <T>(Guid id) { GetOrCreateTable(typeof(T)); using (var command = _conn.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = String.Format(@"Delete FROM {0} WHERE id = :id;", _tableInfo.TableNameWithSchema(typeof(T))); command.Parameters.AddWithValue(":id", id); command.ExecuteNonQuery(); } }
protected override Expression VisitMethodCall(MethodCallExpression node) { if (node.Method.DeclaringType == typeof(Queryable)) { switch (node.Method.Name) { case "Where": { Type elementType = TypeSystem.GetElementType(node.Type); _sb.Append(string.Format("select {0} from {1} where {0} ", columnName, _tableInfo.TableNameWithSchema(elementType))); //Visit(node.Arguments[0]); LambdaExpression lambda = (LambdaExpression)StripQuotes(node.Arguments[1]); Visit(lambda.Body); return(node); } case "Take": { _limit.Append(" limit "); VisitLimit((ConstantExpression)node.Arguments[1]); VisitMethodCall((MethodCallExpression)node.Arguments[0]); return(node); } case "Skip": { _offset.Append(" offset "); VisitOffset((ConstantExpression)node.Arguments[1]); VisitMethodCall((MethodCallExpression)node.Arguments[0]); return(node); } case "OrderBy": { Type elementType = TypeSystem.GetElementType(node.Type); LambdaExpression lambda = (LambdaExpression)StripQuotes(node.Arguments[1]); VisitOrderBy((MemberExpression)lambda.Body); VisitMethodCall((MethodCallExpression)node.Arguments[0]); return(node); } case "OrderByDescending": { Type elementType = TypeSystem.GetElementType(node.Type); LambdaExpression lambda = (LambdaExpression)StripQuotes(node.Arguments[1]); VisitOrderByDesc((MemberExpression)lambda.Body); VisitMethodCall((MethodCallExpression)node.Arguments[0]); return(node); } } } throw new NotSupportedException(string.Format("The method '{0}' is not supported", node.Method.Name)); }