Relative Fields Accessing

Posts   
 
    
Rami
User
Posts: 4
Joined: 01-Oct-2017
# Posted on: 01-Oct-2017 08:36:54   

Dear All, After Greeting

I have some problem when using LLBLGen Pro 5.2. This problem is to accessing relative fields from entity to another. For example, I have (Employees) and (Departments) table joined by (Department_Id) field. I can't access the department name in (Departments) table from (Employee) entity although there is a physical link between these tables. Please, help me to solve this problem. Thank you

Best Regards;

Rami

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Oct-2017 07:35:48   

Hi Rami.

Are you using Adapter or SelfServicing? Did you use PrefetchPaths

Please show us the relevant code and what do you expect.

David Elizondo | LLBLGen Support Team
Rami
User
Posts: 4
Joined: 01-Oct-2017
# Posted on: 02-Oct-2017 09:02:45   

Hi daelmo,

At first, thank you so much for your reply. I am .Net developer and I use LLBLGen Pro to generate my data access layer (DAL). I use SelfServicing template group. Now, I have employees grid view in my page and I want to show department name from department table inside this grid but I can't, the department name column is appear empty although there is a physical link between these tables. I've attached the grid view image for you. Thank you again daelmo.

Best Regards;

Rami

Attachments
Filename File size Added on Approval
Grid.PNG 46,318 02-Oct-2017 09:03.23 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 02-Oct-2017 14:59:52   

you have to specify what code you use to fetch the employees data. Please just copy/paste the relevant code here, no need for making a screenshot of a piece of code wink

You're sure the 'Department.DepartmentName' is the right navigation?

Frans Bouma | Lead developer LLBLGen Pro
Rami
User
Posts: 4
Joined: 01-Oct-2017
# Posted on: 02-Oct-2017 16:51:38   

Dear Otis,

After Greetings...

I am using this code to fetch the employees data into grid :

EmployeeCollection employees = new EmployeeCollection(); employees.GetMulti(null); if (employees.Count > 0 ) { gvEmployees.DataSource = employees; gvEmployees.DataBind(); }

Also, I am sure the 'Department.DepartmentName' is the right navigation. To ensure that, look to employees entity :

EmployeeEntity emp = new EmployeeEntity(1); string deptName = emp.Department.DepartmentName;

The DepartmentName value will be return empty.

Thank you Otis

Best Regards;

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 02-Oct-2017 16:58:42   

Yes, so you have to specify a prefetch path like David suggested, to load the related departments (the department is empty). In theory it should trigger lazy loading but it's bad to it this way as you get a lot of queries (one per row), as it's a typical SELECT N+1 problem, so you should use a prefetch path to fetch the department together with the employee collection. (https://www.llblgen.com/Documentation/5.2/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/SelfServicing/gencode_prefetchpaths.htm)

Are you sure the employee with id '1' has a related department in the database? Have you enabled tracing (https://www.llblgen.com/Documentation/5.2/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/gencode_troubleshootingdebugging.htm) to see what queries are generated?

Frans Bouma | Lead developer LLBLGen Pro
Rami
User
Posts: 4
Joined: 01-Oct-2017
# Posted on: 02-Oct-2017 19:22:02   

Dear David, Dear Frans,

Thank you so much. I used prefetch path and it is work fine now. Thanks again for your help. simple_smile

Best Regards;

Rami