Getting entity collection with specific source table

Posts   
 
    
MJ_01
User
Posts: 17
Joined: 16-Jun-2017
# Posted on: 16-Jun-2017 00:22:27   

I need to get an entity collection using a different source.

Select Table2.IdTable2 from Table1 left join Table2 on Table1.IdTable2 = Table2.IdTable2 left join Table3 on Table3.IdTable3 = Table2.IdTable2 Where Table1.IdTable1 = 100

However, I cannot find information on how to set the initial source table with LLBLGen. Any help is very much appreciated. Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-Jun-2017 07:41:32   

There are multiple ways of doing this. For instance, Linq2LLBL:

var q = from c in metaData.Customer
        join o in metaData.Order on c.CustomerId equals o.CustomerId 
        where o.EmployeeId > 4
        select o.OrderDate;

Another option is using a DynamicList.

Does that make sense to you?

BTW, What LLBLGen version are you using? What template set (Adapter or SelfServicing)?

David Elizondo | LLBLGen Support Team
MJ_01
User
Posts: 17
Joined: 16-Jun-2017
# Posted on: 16-Jun-2017 19:43:03   

LLBLGen Pro 3.5 Final - SelfServicing.

It does make sense. I would like to stick to using Entities and EntityCollections if at all possible. I did take a look at QueryFactory and I thought that logically this should have worked,

var qf = new QueryFactory();
var q = qf.Create()
    .Select(Table2Fields.IdTable2)
    .From(qf.Table1
        .LeftJoin(Table1lEntity.Relations.Table2EntityUsingIdTable1)
        .LeftJoin(Table2Entity.Relations.Table3EntityUsingIdTable3))
    .Where(Table1Fields.IdTable1 == 1);

However the from clause doesn't seem right. I don't see any indication that it's using the desired source table. Used q.ToString to get this:

...
FROM
        RelationCollection:
                EntityRelation:
                        Table1Entity.(IdTable1) 1:n Table2Entity.(IdTable1)
                EntityRelation:
                        Table2Entity.(IdTable3) m:1 Table3Entity.(IdTable3)
...

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Jun-2017 08:14:13   

I think it's right. Please see the Generated SQL.

David Elizondo | LLBLGen Support Team
MJ_01
User
Posts: 17
Joined: 16-Jun-2017
# Posted on: 20-Jun-2017 00:44:30   

Thank you very much for that link! After setting the proper values, I can confirm that it is generating the proper query!