Inner Join with Subsonic

inner-joinsubsonic

I am trying to display all records that match the last name entered into a textbox.
This requires an INNER JOIN on the "volID" column because there are 2 tables.

<asp:TextBox ID="lName" runat="server"></asp:TextBox>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true" Visible="true"></asp:GridView>
<asp:linkButton ID="btnSubmit" runat="server" onclick="btnSubmit_Click" />

Code behind:

 protected void btnSubmit_Click(object sender, EventArgs e)
    {
            GridView1.DataSource = new Select("*")
            .From(PastAwardName.Schema)
            .InnerJoin(PastAwardName.VolIDColumn, PastAwardType.VolIDColumn)
            .Where(PastAwardName.Columns.LName).IsEqualTo(this.lName.Text)
            .ExecuteReader();

            GridView1.DataBind();
    }

I tried to do this from and example on Subsonics site but cannot get it working. Geeting the error below.

Server Error in '/' Application. 
________________________________________
The objects "dbo.pastAwardNames" and "dbo.pastAwardNames" in the FROM clause have the same exposed names. Use correlation names to distinguish them. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: The objects "dbo.pastAwardNames" and "dbo.pastAwardNames" in the FROM clause have the same exposed names. Use correlation names to distinguish them.

Source Error: 

Line 30: 
Line 31: 
Line 32:         GridView1.DataSource = new Select("*")
Line 33:             .From(PastAwardName.Schema)
Line 34:             .InnerJoin(PastAwardName.VolIDColumn, PastAwardType.VolIDColumn)

Best Answer

I had a similar problem to this, and discovered this page by searching on the error text "in the FROM clause have the same exposed names" and SubSonic 2.2.

Anyway, thought I would post my code, which works perfectly in Subsonic 2.2 and looks quite clean..

Hope somebody finds it useful as it had me scratching my head for a while!!

IDataReader reader = new SubSonic.Select(CityMapping.MasterCityColumn, CityMapping.ChildCityColumn, CityMappingTourType.TourTypeCodeColumn)
                .From<CityMapping>()
                .InnerJoin(CityMappingTourType.CityMappingIDColumn, CityMapping.IdColumn)
                .OrderAsc(CityMapping.Columns.MasterCity, CityMapping.Columns.ChildCity, CityMappingTourType.Columns.TourTypeCode)
                .ExecuteReader();
Related Topic