Help on using prefetch

Posts   
 
    
Stephan
User
Posts: 63
Joined: 16-Jan-2007
# Posted on: 10-Sep-2007 16:36:03   

Hi I'm (trying to) using the prefetch to get related records but on render I have the following message:

{"The multi-part identifier \"Mextra.dbo.IBPWorkPlan.IBPDiscipline_Id\" could not be bound."}

When examining the the exception I filtered the generated query and tried to run it in the QA, here it throws the exception:

The multi-part identifier "Mextra.dbo.IBPWorkPlan.IBPDiscipline_Id" could not be bound.

SELECT [Mextra].[dbo].[IBPWorkGoal].[IBPWorkGoalID] AS [IbpworkGoalId], [Mextra].[dbo].[IBPWorkGoal].[Description], [Mextra].[dbo].[IBPWorkGoal].[StartDate], [Mextra].[dbo].[IBPWorkGoal].[EndDate], [Mextra].[dbo].[IBPWorkGoal].[GasScore], [Mextra].[dbo].[IBPWorkGoal].[IBPMainGoal_Id] AS [IbpmainGoalId], [Mextra].[dbo].[IBPWorkGoal].[User_Id] AS [UserId] FROM [Mextra].[dbo].[IBPWorkGoal] WHERE ( ( [Mextra].[dbo].[IBPWorkGoal].[IBPMainGoal_Id] = @IbpmainGoalId1 AND [Mextra].[dbo].[IBPWorkGoal].[StartDate] >= @StartDate2 AND [Mextra].[dbo].[IBPWorkGoal].[EndDate] < @EndDate3 AND [Mextra].[dbo].[IBPWorkPlan].[IBPDiscipline_Id] IN (@IbpdisciplineId4)))

What I'm I doing wrong? The WorkPlan has a relations with the WorkGoal and each workGoal can have multiple workplans.

Any help appreciated. Thanks

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 11-Sep-2007 11:34:24   

Please post the corresponding code snippet.

Stephan
User
Posts: 63
Joined: 16-Jan-2007
# Posted on: 11-Sep-2007 21:27:17   

Hi Walaa, not exactly the same but the problem is the same:

An exception was caught during the execution of a retrieval query: The multi-part identifier "Mextra.dbo.IBPMain.IBPMainID" could not be bound.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.


   EntityCollection<IbpDailyReportEntity> myCollection = new EntityCollection<IbpDailyReportEntity>(new IbpDailyReportEntityFactory());
            IRelationPredicateBucket filter = new RelationPredicateBucket();
            //filter.PredicateExpression.Add(IbpDailyReportFields.UserId == userId);

            //Want to use to show user who reported.
            //IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.IbpDailyReportEntity);
            //prefetchPath.Add(IbpDailyReportEntity);

            //Only reports for the current IBP
            filter.Relations.Add(IbpDailyReportEntity.Relations.IbpWorkPlanEntityUsingIbpWorkPlanId);
            filter.Relations.Add(IbpWorkPlanEntity.Relations.IbpWorkGoalEntityUsingIbpworkGoalId);
            filter.Relations.Add(IbpWorkGoalEntity.Relations.IbpMainGoalEntityUsingIbpmainGoalId);

            filter.PredicateExpression.Add(IbpMainFields.IbpmainId == IbpMainId);

            if (startDate.HasValue)
            {
                filter.PredicateExpression.Add((IbpDailyReportFields.ReportDate >= startDate));
            }
            if (endDate.HasValue)
            {
                filter.PredicateExpression.Add((IbpDailyReportFields.ReportDate < endDate));
            }

            if (!workGoalIds.Count.Equals(0))
            {
                filter.Relations.Add(IbpDailyReportEntity.Relations.IbpWorkPlanEntityUsingIbpWorkPlanId);
                filter.PredicateExpression.Add(IbpWorkPlanFields.IbpworkGoalId == workGoalIds);
            }
            
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(myCollection, filter);
            }
            return myCollection;

The flow looks like: DailyReport <- WorkPlan <- WorkGoal <- Main

I want to have all the lines (stored in DailyReport) where the id of the main-entity is some value (i.e. 9), and some other filters of course. If I remove the filter for IbpMainFields.IbpmainId == IbpMainId everything runs fine.

Any suggestions?

B.t.w. if I run the generated query I also get an error, but I'm a little stuck on this one.

Stephan
User
Posts: 63
Joined: 16-Jan-2007
# Posted on: 11-Sep-2007 22:02:53   

Sorry, found the problem I missed some relations so the Id could never be compared.

To be exact:



filter.Relations.Add(IbpDailyReportEntity.Relations.IbpWorkPlanEntityUsingIbpWorkPlanId); 
           filter.Relations.Add(IbpWorkPlanEntity.Relations.IbpWorkGoalEntityUsingIbpworkGoalId);

filter.Relations.Add(IbpWorkGoalEntity.Relations.IbpMainGoalEntityUsingIbpmainGoalId);


would become

        filter.Relations.Add(IbpDailyReportEntity.Relations.IbpWorkPlanEntityUsingIbpWorkPlanId);
        filter.Relations.Add(IbpWorkPlanEntity.Relations.IbpWorkGoalEntityUsingIbpworkGoalId);   
     filter.Relations.Add(IbpWorkGoalEntity.Relations.IbpMainGoalEntityUsingIbpmainGoalId);     

filter.Relations.Add(IbpMainGoalEntity.Relations.IbpPerspectiveEntityUsingIbpPerspectiveId);

filter.Relations.Add(IbpPerspectiveEntity.Relations.IbpMainEntityUsingIbpMainId);

two extra relations.

Thanks for the time