列在亚音速选择造成的问题的多个表同名 [英] Column with same name in multiple tables causing problem in SubSonic Select
问题描述
有其他问题(至少2我看过他们)与此类似,但我不能这样使用它们来解决。
there are other question (at least 2 I've seen them) similar to this but I'm not able to solve this using them.
现在的问题:我有3台从我需要选择只有4列。我使用InnerJoin,它是可以正常使用。当我添加在哪里这个问题的选择开始。我有一个在两个表名为名称列。如果我添加了简单
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.."
如果我使用完全合格的列名(作为前缀列名表),它说,必须声明参数@TABLE_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!
推荐答案
如果您在列对象的Where语句亚音速将使用它的全名,而不是修建字符串传递。你可以找到的对象作为静态属性在列,所以在这种情况下,如果你调用一个对象TableOne你可以用TableOne.NameColumn,并传递到哪里()
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():
...
sq.Where(TableTwo.NameColumn).Like("A%");
这篇关于列在亚音速选择造成的问题的多个表同名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!