PrefetchPath and 2 level fetch

Posts   
 
    
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 03-Feb-2010 16:04:36   

Hello there..

Hierarchy structure of my entities looks like this:

Company -> Department -> Employee

Is it possible to fetch all this in one fetch ?

So far I comed up with this:


            DataAccessAdapter adapter = new DataAccessAdapter();

            var company = new CompanyEntity(1);

            IPrefetchPath2 prefetchPath = new PrefetchPath2(EntityType.CompanyEntity);

            prefetchPath.Add(CompanyEntity.PrefetchPathDepartment);

            adapter.FetchEntity(company, prefetchPath);

            var department = company.Department.FirstOrDefault(x => x.Id == 16);

            IPrefetchPath2 prefetchPath2 = new PrefetchPath2(EntityType.DepartmentEntity);

            prefetchPath2.Add(DepartmentEntity.PrefetchPathEmployee);

            adapter.FetchEntity(department, prefetchPath2);

Or is there any more convenient way to achieve the same result?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 03-Feb-2010 16:20:11   

Here you are:

            DataAccessAdapter adapter = new DataAccessAdapter();
            var company = new CompanyEntity(1);
            IPrefetchPath2 prefetchPath = new PrefetchPath2(EntityType.CompanyEntity);

            prefetchPath.Add(CompanyEntity.PrefetchPathDepartment).SubPath.Add(DepartementEntity.PrefetchPathEmployee);

            adapter.FetchEntity(company, prefetchPath);
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 04-Feb-2010 10:27:21   

Great! Exactly what I needed.. thank you