LLBLGen: 5.3.3
.net 4.6.1
Adapter Template
Postgres 9.4
I'm new to Derived Models, but it looks like a great idea. I just need to learn how to use it.
To start, I created a new Derived Model (DTO) with a root entity along with some child objects.
I added the fields that I wanted displayed. Then in the Shape Editor, I de-normalized it so the shape is only two levels deep, where the true hierarchy is about 4.
It looks good from the designer.
I generated the llblgen code and when I try to use it, I followed the example in the documentation:
List<Customer> results = null;
using(var adapter = new DataAccessAdapter())
{
var metaData = new LinqMetaData(adapter);
var q = (from c in metaData.Customer
where c.VisitingAddressCountry == "USA"
select c)
.ProjectToCustomer();
results = q.ToList();
}
at http://www.llblgen.com/Documentation/5.1/Derived%20Models/dto_llblgen.htm
I used this code exactly, replacing the dto, entity, and filter column names with my own.
And what I noticed was that it automatically prefetched one entity (where the FK was on the root node). E.g My root is 'TransactEntity'. It has a 'SellerId'. The 'SellerEntity' data was automatically prefetched. However, there is an 'LcEntity' that has a 'TransactId'. The 'LcEntity' data was not automatically prefetched. Is this normal behavior?
I did a little bit of studying, and I found this regarding prefetches:
var q = (from c in metaData.Customer
where c.Country == "Germany"
select c).WithPath(customerPath=>customerPath
.Prefetch<OrderEntity>(c=>c.Orders)
.FilterOn(o=>o.EmployeeId==2)
.SubPath(orderPath=>orderPath.Prefetch(o => o.Employee))
.Prefetch<EmployeeEntity>(c=>c.EmployeeCollectionViaOrder));
at https://www.llblgen.com/Documentation/5.3/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/Linq/gencode_linq_prefetchpaths.htm#multiple-nodes-at-the-same-level
So I'm wondering if I need to add the prefetches to the query. But if so, do I not add the prefetch that is happening automatically (i.e. the SellerEntity that is automatically loading)?
It's confusing to me, why it chooses to prefetch some entities, but not the others. I suppose it has to do with it prefetching the child if the FK is on the parent... but I didn't pick up on any of this in the documentation.
I can share the llblgen project if that helps, but I'd like to move that to a private channel.