Searching using prefetch paths and relations.

Posts   
 
    
JeffM
User
Posts: 29
Joined: 30-Dec-2006
# Posted on: 15-Jun-2007 06:03:45   

Where to start. i have a request entity which has status, salesrep, and a mapped on related field company. I understand using the prefetchpath to gain access to the mapped on related field. How can I use it to filter data the code below gives the following error.

The multi-part identifier "SiteSurvey.dbo.Customer.CustomerName" could not be bound. 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 multi-part identifier "SiteSurvey.dbo.Customer.CustomerName" could not be bound.

Source Error:

Line 22: Using adapter As New DataAccessAdapter() Line 23: 'Refresh entities in container Line 24: adapter.FetchEntityCollection(requestDS_A.EntityCollection, bucket, prefetchPath) Line 25: End Using Line 26: GridView1.DataBind()

The code follows


Dim bucket As New RelationPredicateBucket()
        bucket.PredicateExpression.Add(RequestFields.Status Mod "%call%").AddWithAnd(RequestFields.RepId Mod ("%" + Me.SalesReps.SelectedValue.ToString + "%")).AddWithAnd(CustomerFields.Name Mod ("%" + Me.Company.Text + "%"))
        Dim prefetchPath As IPrefetchPath2 = New PrefetchPath2(CType(EntityType.RequestEntity, Integer))
        prefetchPath.Add(RequestEntity.PrefetchPathEmployeesOmd)
        prefetchPath.Add(RequestEntity.PrefetchPathCustomer)
        Using adapter As New DataAccessAdapter()
            'Refresh entities in container
            adapter.FetchEntityCollection(requestDS_A.EntityCollection, bucket, prefetchPath)
        End Using
        GridView1.DataBind()
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 15-Jun-2007 08:32:48   

You are fetching Requests, and you have a filter on CustomerFields.Name, that's from the Customer table, then you should add a relation (from Requests to Customer) to the RelationPredicateBucket.Relations collection.

JeffM
User
Posts: 29
Joined: 30-Dec-2006
# Posted on: 18-Jun-2007 19:43:06   

Thank you for that information that worked for the above problem. Now I have another related problem regarding Sorting a gridview on a mapped field. Sorting works for everything else. Here is my code then below. I want to be able to sort installing tech, status, and company name. installing tech, and status work but company name is a related field, doesn't work The gridview


<asp:GridView ID="requestGV" runat="server" AutoGenerateColumns="False"
                                DataKeyNames="Rrid" DataSourceID="requestDS_A" AllowSorting="True" SkinID="light">
                                <Columns>
                                    <asp:TemplateField ShowHeader="False">
                                        <EditItemTemplate>
                                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                                                Text="Update"></asp:LinkButton>
                                            <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                                Text="Cancel"></asp:LinkButton>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                                                Text="Edit"></asp:LinkButton>
                                            <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
                                                Text="Delete"></asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="Crid" HeaderText="Crid" InsertVisible="False" ReadOnly="True" />
                                    <asp:BoundField DataField="CustomerName" HeaderText="Name" SortExpression="Name" />
                                    <asp:BoundField DataField="Rrid" HeaderText="Rrid" ReadOnly="True" InsertVisible="False" />
                                    <asp:BoundField DataField="FullName" HeaderText="Sales Rep" />
                                    <asp:BoundField DataField="SubmittedDate" HeaderText="SubmittedDate" />
                                    <asp:BoundField DataField="DeliveryDate" HeaderText="DeliveryDate" />
                                    <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
                                    <asp:BoundField DataField="OldStatus" HeaderText="OldStatus" />
                                    <asp:BoundField DataField="SurveyCompletelInitials" HeaderText="SurveyCompletelInitials" />
                                    <asp:BoundField DataField="SurveyCompleteDate" HeaderText="SurveyCompleteDate" />
                                    <asp:BoundField DataField="InstallTechnician" HeaderText="InstallTechnician" SortExpression="InstallTechnician" />
                                    <asp:BoundField DataField="InstallTime" HeaderText="InstallTime" />
                                </Columns>
                            </asp:GridView>

and the perform select on datasource.


'perform select is used by the llblgen datasource to bind data found in the database to the control
    Sub requestDS_A_PerformSelect(ByVal sender As Object, ByVal e As PerformSelectEventArgs2) Handles requestDS_A.PerformSelect
        Dim bucket As New RelationPredicateBucket()
        bucket.Relations.Add(New EntityRelation(RequestFields.Crid, CustomerFields.Crid, RelationType.ManyToOne))
        Dim prefetchPath As IPrefetchPath2 = New PrefetchPath2(CType(EntityType.RequestEntity, Integer))
        prefetchPath.Add(RequestEntity.PrefetchPathEmployeesOmd)
        prefetchPath.Add(RequestEntity.PrefetchPathCustomer)
        Using adapter As New DataAccessAdapter()
            'Refresh entities in container
            adapter.FetchEntityCollection(requestDS_A.EntityCollection, bucket, 0, e.Sorter, prefetchPath, e.PageNumber, e.PageSize)
        End Using
    End Sub

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Jun-2007 06:14:28   

I think

<asp:BoundField DataField="CustomerName" HeaderText="Name" SortExpression="Name" />

must be

<asp:BoundField DataField="CustomerName" HeaderText="Name" SortExpression="CustomerName" />
David Elizondo | LLBLGen Support Team
JeffM
User
Posts: 29
Joined: 30-Dec-2006
# Posted on: 20-Jun-2007 22:07:10   

I tried the above already. It doesnot sort by CustomerName with the sort expression set to"CustomerName" . I tried server side sort vs client side sort? as well. hmmmm!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Jun-2007 05:32:53   
David Elizondo | LLBLGen Support Team