I have tables Users, Widgets and Layouts. Users have many-to-many relationship with Widgets via Layouts. Each Layout has UserID and WidgetID. I want to delete a Layout that matches specific UserID and WidgetID.
Using SubSonic 3 ActiveRecord I write:
Layout.Delete(x => x.UserID == user.id && x.WidgetID == id);
However, SubSonic deletes all widget layouts for the user, seemingly ignoring the second part of the condition. Am I doing it wrong, or is this a SubSonic bug? If latter, are there any workarounds?
Added later: I fixed it temporarily in Context.tt in my project's Models subdirectory:
diff --git a/Models/Context.tt b/Models/Context.tt
index ee64200..dd47510 100644
--- a/Models/Context.tt
+++ b/Models/Context.tt
@@ -162,8 +162,8 @@ namespace <#=Namespace#>
         LambdaExpression lamda = column;
         SqlQuery result = new Delete<T>(this.Provider);
         result = result.From<T>();
-        SubSonic.Query.Constraint c = lamda.ParseConstraint();
-        result.Constraints.Add(c);
+        var q = new QueryVisitor();
+        result.Constraints.AddRange(q.GetConstraints(lamda));
         return result;
     }