InnerJoin 与Where 表达式问题
我正在使用 Subsonic 2.1,我需要进行内连接并使用 where 表达式,但我不断收到错误:
Must declare the scalar variable "@Partner"
这是我的代码:
Dim ds As DataSet = UWP.Model.DB.Select("TOP 30 FirstName, LastName, EmailAddress, CustomerRowID, CompanyName")
.From("Customer").InnerJoin("Partner")
.Where("Partner.PartnerID").IsEqualTo("Customer.PartnerID")
.WhereExpression("FirstName").Like("%" & SearchTerm & "%")
.Or("LastName").Like("%" & SearchTerm & "%")
.Or("EmailAddress").Like("%" & SearchTerm & "%")
.CloseExpression()
.ExecuteDataSet()
我尝试过以 10 种不同的方式重新排列这个东西,但似乎无法得到它正确的。
I am using Subsonic 2.1 and I need to do an innerjoin and use a where expression and I keep getting the error:
Must declare the scalar variable "@Partner"
Here is my code:
Dim ds As DataSet = UWP.Model.DB.Select("TOP 30 FirstName, LastName, EmailAddress, CustomerRowID, CompanyName")
.From("Customer").InnerJoin("Partner")
.Where("Partner.PartnerID").IsEqualTo("Customer.PartnerID")
.WhereExpression("FirstName").Like("%" & SearchTerm & "%")
.Or("LastName").Like("%" & SearchTerm & "%")
.Or("EmailAddress").Like("%" & SearchTerm & "%")
.CloseExpression()
.ExecuteDataSet()
I have tried re-arranging this thing about 10 different ways and just can't seem to get it right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在 where 子句中而不是在联接本身中指定联接条件是否有原因?
我重写了您的查询以利用强类型列名,您应该尽可能这样做,因为您可以在编译时而不是运行时捕获问题。另外,使用 .ContainsString() 而不是串联的繁文缛节,以获得更好的可读性。
或者要使用原始代码,只需使用内部联接的四个字符串重载并指定其中的列。我认为当你并不真正需要时,你会因为尝试在 where 子句中进行连接而被绊倒。
Is there a reason you specify the join criteria in the where clause instead of in the join itself?
I re-wrote your query to take advantage of strongly typed column names, which you should do whenever possible because you can catch problems at compile time instead of run time. Also, use .ContainsString() instead of that concatenated gobblydegook for better readability.
Or to use your original code, just use the four string overload of inner join and specify the columns there. I think you're getting tripped up by trying to do the join in the where clause when you don't really need to.
.InnerJoin("合作伙伴 p")..Where("p.PartnerID") ?
我以前从未见过这个,所以我真的只是猜测。所以如果我只是愚蠢的话请忽略我:p
.InnerJoin("Partner p")..Where("p.PartnerID") ?
I have never seen this before, so i'm really just guessing. So ignore me if i'm just being stupid :p
有两种方法可以进行亚音速内连接。第一种方法是指定要链接的列,例如:
如果已在 SubSonic 模型中设置关系,则只需指定表,而无需指定列。看起来这就是您想要做的,但您的语法不太正确。您必须使用泛型,如下所示:
第二种方法是更好的选择,因为它更具可读性。但是,它仅在尝试连接您在 From() 函数中指定的表时才有效。在这种情况下它应该对你有用。
There are 2 ways to do an inner join with subsonic. The first way is to specify the columns to link on, such as:
If the relationships is already setup in your SubSonic model, you can just specify the table, without having to specify the columns. It looks like this is what you were trying to do, but you didn't have the syntax quite right. You must use generics, like this:
The second way is preferrable because it is more readable. However, it only works when trying to join with the table that you specify in the From() function. It should work for you in this situation.