self-referencing question

Posts   
 
    
medvjed
User
Posts: 4
Joined: 03-Feb-2007
# Posted on: 03-Feb-2007 09:20:19   

I'm using llbgenpro 2.0 with .net 2.0, sql2005, and adapter

I'm experimenting with the adventure works database. the employee table is selfreferencing (employee - manager) and references Contact table.

I want to prefetch one employee (a manager) and all of his subordinates. I also want to prefetch his contact info and all contact info of his subordinates.

I tried this

        IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.EmployeeEntity);
        prefetchPath.Add(EmployeeEntity.PrefetchPathContact);
        prefetchPath.Add(EmployeeEntity.PrefetchPathSubOrdinateEmployees.SubPath.Add( EmployeeEntity.PrefetchPathContact));

but i get an exception:

System.ArgumentException was unhandled Message="The PrefetchPathElement you to tried to add is already added to this PrefetchPath.\r\nParameter name: elementToAdd" Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20" ParamName="elementToAdd" StackTrace: at SD.LLBLGen.Pro.ORMSupportClasses.PrefetchPath2.Add(IPrefetchPathElement2 elementToAdd, Int32 maxAmountOfItemsToReturn, IPredicateExpression additionalFilter, IRelationCollection additionalFilterRelations, ISortExpression additionalSorter, IEntityFactory2 entityFactoryToUse) at SD.LLBLGen.Pro.ORMSupportClasses.PrefetchPath2.Add(IPrefetchPathElement2 elementToAdd) at ConsoleApplication1.Program.Main(String[] args) in C:\ConsoleApplication1\Program.cs:line 27 at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 04-Feb-2007 00:30:36   

I think you just have a misplaced parentheses. This code works for me:


DataAccessAdapter adapter = new DataAccessAdapter();
EmployeeEntity manager = new EmployeeEntity(3);  //get a manager
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.EmployeeEntity);
prefetchPath.Add(EmployeeEntity.PrefetchPathEmployeeManagerIdXemployeeId).SubPath.Add( EmployeeEntity.PrefetchPathContactIdXcontact);
prefetchPath.Add(EmployeeEntity.PrefetchPathContactIdXcontact);
adapter.FetchEntity(manager, prefetchPath);

So I think you just need to change this line:

prefetchPath.Add(EmployeeEntity.PrefetchPathSubOrdinateEmployees.SubPath.Add( EmployeeEntity.PrefetchPathContact));

...to this...

prefetchPath.Add(EmployeeEntity.PrefetchPathSubOrdinateEmployees).SubPath.Add( EmployeeEntity.PrefetchPathContact);