SubSonic 3 ActiveRecord lambda 表达式在删除时部分被忽略
我有表用户、小部件和布局。 用户通过布局与小部件建立多对多关系。 每个Layout都有UserID和WidgetID。 我想删除与特定 UserID 和 WidgetID 匹配的布局。
使用 SubSonic 3 ActiveRecord 我写道:
Layout.Delete(x => x.UserID == user.id && x.WidgetID == id);
但是,SubSonic 删除了用户的所有小部件布局,似乎忽略了条件的第二部分。 是我做错了,还是这是 SubSonic 的错误? 如果是后者,有什么解决方法吗?
后来添加:我在项目的 Models 子目录中的 Context.tt 中临时修复了它:
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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,这似乎是 SubSonic 中的一个错误。 您应该将其报告给 github
同时,此代码可能会解决该问题:
Seems like a bug in SubSonic to me. You should report it to github
In the meantime this code might workaround the issue: