Skip polymorphic joins in linq

Posts   
 
    
hotchill avatar
hotchill
User
Posts: 180
Joined: 22-Jan-2007
# Posted on: 12-Oct-2018 14:22:17   

Hi.

Is it possible to get rid of the polymorphic joins in the below expression? I only need a single field from the base table.

var enqs = new LinqMetaData(adapter).Enquiry.Where(e => e.AddedByUserId == CurrentUserId && e.ParentEnquiryId == null).OrderByDescending(e => e.Added).IncludeFields(e => e.ServiceId).Take(1000).ToList();

5.4 (5.4.0) RTM using Adapter.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Oct-2018 06:46:12   

Hi Tore ,

Could you please explain the involved hierarchy? (i.e.: what entities are involved and how they are related to each other, Is it Inheritance per entity or Inheritance per entity hierarchy?)

David Elizondo | LLBLGen Support Team
hotchill avatar
hotchill
User
Posts: 180
Joined: 22-Jan-2007
# Posted on: 14-Oct-2018 00:34:15   

Hi David.

Enquiry is the super-type entity. It has several sub-types such as PersonRegistrationEnquiry.

I think it is "inheritance per entity hierarchy". I have one table per type/entity in my db.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Oct-2018 07:50:31   

If it's superentity and the filter fields are from supertype, the generated query should contain only the super table query. Do you see something different? If so, please explain steps to reproduce it (DDL for your involved tables at least).

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 15-Oct-2018 09:33:52   

For entity fetches, like the one you're doing, all subtypes are fetched as well, as subtypes are of the supertype as well. If you want just the supertypes, you have to fetch a projection and only specify the supertype's fields.

Frans Bouma | Lead developer LLBLGen Pro
hotchill avatar
hotchill
User
Posts: 180
Joined: 22-Jan-2007
# Posted on: 15-Oct-2018 12:25:11   

Thanks. Less appealing syntax, but this should do it.

var q = qf.Enquiry
                    .Select(() => new EnquiryEntity {
                        ServiceId = EnquiryFields.ServiceId.ToValue<long>()
                    }).Where(EnquiryFields.AddedByUserId == CurrentUserId &  EnquiryFields.ParentEnquiryId == DBNull.Value)
                    .OrderBy(EnquiryFields.Added | SortOperator.Descending)
                    .Page(1, 1000);
                var enqs = adapter.FetchQuery(q);