Problem with a dynamic list

Posts   
 
    
JMitchell avatar
JMitchell
User
Posts: 128
Joined: 01-Sep-2006
# Posted on: 22-May-2007 12:07:45   

Sorry if this is the wrong area for this query.

I'm getting the following error:

Relation at index 1 doesn't contain an entity already added to the FROM clause. Bad alias?

My code is:


        Dim results As New System.Data.DataTable()
        Dim fields As New ResultsetFields(4)
        fields.DefineField(TrainingCourseFields.Summary, 0)
        fields.DefineField(TrainingSessionFields.Capacity, 1)
        fields.DefineField(TrainingBookingFields.EmployeeId, 2)
        fields.DefineField(EmployeeFields.Name, 3)
        fields(1).AggregateFunctionToApply = AggregateFunction.Sum
        fields(2).AggregateFunctionToApply = AggregateFunction.Count
        Dim relations As IRelationCollection = New RelationCollection()
        relations.Add(Training.EntityClasses.EmployeeEntity.Relations.TrainingCourseEntityUsingTrainer)
        relations.Add(Training.EntityClasses.TrainingBookingEntity.Relations.TrainingSessionEntityUsingSessionId)
        relations.Add(Training.EntityClasses.TrainingCourseEntity.Relations.TrainingSessionEntityUsingCourseId)
        Dim groupByClause As IGroupByCollection = New GroupByCollection()
        groupByClause.Add(fields(0))
        groupByClause.Add(fields(1))
        groupByClause.Add(fields(3))
        Dim CustomerDynamicList As New Training.DaoClasses.TypedListDAO()
        CustomerDynamicList.GetMultiAsDataTable(fields, results, 0, Nothing, Nothing, relations, False, Nothing, Nothing, 0, 0)
        rptCourses.DataSource = results
        rptCourses.DataBind()

I'm using LLBLGen Pro 2.0, Visual Studio 2005 with VB for an ASP web page.

I don't know if this has anything to do with my Employee table having relations to both the TrainingCourse and TrainingBooking tables?

JMitchell avatar
JMitchell
User
Posts: 128
Joined: 01-Sep-2006
# Posted on: 22-May-2007 12:49:17   

I've sorted it now. I rearranged the relations which I think was causing the problem. I also added the groupByClause into the call but I don't think that was affecting the error I was getting - that gave me a whole different error after I fixed the first one!

Working code is:

        Dim results As New System.Data.DataTable()
        Dim fields As New ResultsetFields(4)
        fields.DefineField(TrainingCourseFields.Summary, 0)
        fields.DefineField(TrainingSessionFields.Capacity, 1, "TotalCapacity")
        fields.DefineField(TrainingBookingFields.EmployeeId, 2, "TotalBookings")
        fields.DefineField(EmployeeFields.Name, 3, "Trainer")
        fields(1).AggregateFunctionToApply = AggregateFunction.Sum
        fields(2).AggregateFunctionToApply = AggregateFunction.Count
        Dim relations As IRelationCollection = New RelationCollection()
        relations.Add(Training.EntityClasses.TrainingCourseEntity.Relations.TrainingSessionEntityUsingCourseId)
        relations.Add(Training.EntityClasses.TrainingSessionEntity.Relations.TrainingBookingEntityUsingSessionId)
        relations.Add(Training.EntityClasses.EmployeeEntity.Relations.TrainingCourseEntityUsingTrainer)
        Dim groupByClause As IGroupByCollection = New GroupByCollection()
        groupByClause.Add(fields(0))
        groupByClause.Add(fields(1))
        groupByClause.Add(fields(3))
        Dim CustomerDynamicList As New Training.DaoClasses.TypedListDAO()
        CustomerDynamicList.GetMultiAsDataTable(fields, results, 0, Nothing, Nothing, relations, False, groupByClause, Nothing, 0, 0)
        rptCourses.DataSource = results
        rptCourses.DataBind()