多个表中具有相同名称的列导致 SubSonic Select 出现问题
还有其他问题(至少有 2 个我见过)与此类似,但我无法使用它们解决此问题。
现在的问题是:我有 3 个表,我只需要从中选择 4 列。 我正在使用 InnerJoin,它工作得很好。 当我向此选择添加“位置”时,问题就开始了。 我在两个表中有一个名为“Name”的列。 如果我简单地添加它
.Where("Name").Like("A%")
说“...不明确的列名..”
如果我使用完全限定的列名(表以列名为前缀)它说必须声明参数@TABLE_NAME
SqlQuery sq = new Select(Tables.TableOne + "." + TableOne.Columns.MemberId +
" AS MemberId",
Tables.TableTwo + "." + TableTwo.Columns.Name + " AS MemberName",
Tables.TableOne + "." + TableOne.Columns.ExpiryOn + " AS MembershipExpiresOn",
Tables.TableFour + "." + TableFour.Columns.Name + " AS Country")
.From(DAL.Tables.TableOne)
.InnerJoin(Tables.TableTwo)
.InnerJoin(Tables.TableThree)
.InnerJoin(Tables.TableFour, TableFour.Columns.CountryCode,
Tables.TableThree, TableThree.Columns.CountryOfBirth).
sq.Where(Tables.TableTwo + "." + TableTwo.Columns.Name).Like("A%");
我也尝试传递硬编码字符串但没有任何作用!
there are other question (at least 2 I've seen them) similar to this but I'm not able to solve this using them.
Now the problem: I've 3 table from which I need to select 4 columns only. I'm using InnerJoin and it is working perfectly. Problem starts when I add a Where to this Select. I've a column named "Name" in two tables. If I add simply the
.Where("Name").Like("A%")
It says "... ambiguous column name.."
If I use fully qualified column name (with table prefixed to column name) it says must declare parameter @TABLE_NAME
SqlQuery sq = new Select(Tables.TableOne + "." + TableOne.Columns.MemberId +
" AS MemberId",
Tables.TableTwo + "." + TableTwo.Columns.Name + " AS MemberName",
Tables.TableOne + "." + TableOne.Columns.ExpiryOn + " AS MembershipExpiresOn",
Tables.TableFour + "." + TableFour.Columns.Name + " AS Country")
.From(DAL.Tables.TableOne)
.InnerJoin(Tables.TableTwo)
.InnerJoin(Tables.TableThree)
.InnerJoin(Tables.TableFour, TableFour.Columns.CountryCode,
Tables.TableThree, TableThree.Columns.CountryOfBirth).
sq.Where(Tables.TableTwo + "." + TableTwo.Columns.Name).Like("A%");
I've tried to pass hard-coded string also but nothing works!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您将列对象传递给Where语句,SubSonic将使用它的完全限定名称而不是构建字符串。 您可以在对象上找到作为静态属性的列,因此在这种情况下,如果您有一个名为“TableOne”的对象,您可以使用“TableOne.NameColumn”并将其传递到Where():
If you pass in the column object to the Where statement SubSonic will use it's fully qualified name instead of building a string. You can find the column on the object as a static property, so in this case if you have an object called "TableOne" you can use "TableOne.NameColumn" and pass that into the Where():
以下查询是否有效,我假设您使用的是 2.2:
Does the following query work, I'm assuming you're using 2.2:
我从未使用过它,
但是您是否尝试将最后一行更改为:
I haven't used it ever,
but have your tried to change your last line to: