Expression Clauses in a query

Hello

We are trying to use a join clause in a script on 1IM. The problem we have is that when we are using classes .Join and .On of the object Query, .On class only admit ExpressionClause Type. Is there any example of how to declare and initialize this type?

Thanks in advance,

Adri 

Parents
  • There is no sample as far as I know. But if you try to join over a foreign key column you do not need an ExpressionClause.

    The following sample loads a collection of business roles where the org type (Org.UID_OrgType.Ident_OrgType) is "Business Roles".

    Dim f As ISqlFormatter = Session.SqlFormatter()
    Dim strOrgType As String = String.Empty
    
    strOrgType = "Business roles"
    
    Dim qOrgQuery As Query
    qOrgQuery = Query.From(Table.Org).Join(Table.OrgType, "ot").On(Table.Org.UID_OrgType).Select(Table.OrgType.Ident_OrgType).Where( _
        f.Comparison(String.Format("ot.{0}", Table.OrgType.Ident_OrgType), strOrgType, ValType.String, CompareOperator.Equal))
    
    Dim mycollection As TypedEntityCollection(Of VI.DB.Model.Org) = Session.Source.GetCollection(Of VI.DB.Model.Org)(qOrgQuery, EntityCollectionLoadType.Bulk)
    
    
    Return mycollection.Count.ToString
    

    Please be aware that the join is just usable to identify the data to load. A collection always loads entities of one specific type. You cannot join additional columns to it.

  • Hi Markus

    Is there any way to get value for an element in the collection from joined table?

    elem.GetValue doesn't work, even for generic EntityCollection (not typed)

  • No there isn't. A collection can only return values from the one object type. Option one is to create your own custom r-table that contains the joined values and create a collection from it. Option two is to code the additional data fetching and joining via additional collection loads and lookups in dictionaries or hash tables.

  • I just stumbled upon this answer for the very same issue I have currently.

    It seems you can use the selected columns of a joined table for your where clause but not as returned values.

    That's really a shame, because creating manual selects for each row would be a performance hog in our case and an r-table seems to be overkill just to circumvent this deficiency.

    I might be wrong, but wouldn't it be something that could be added to the collection class? Sth like a sub-collection object for each joined table?

    Not that this would help us here and now, but maybe as a suggestion. Otherwise I really like the fluent interface approach.

Reply
  • I just stumbled upon this answer for the very same issue I have currently.

    It seems you can use the selected columns of a joined table for your where clause but not as returned values.

    That's really a shame, because creating manual selects for each row would be a performance hog in our case and an r-table seems to be overkill just to circumvent this deficiency.

    I might be wrong, but wouldn't it be something that could be added to the collection class? Sth like a sub-collection object for each joined table?

    Not that this would help us here and now, but maybe as a suggestion. Otherwise I really like the fluent interface approach.

Children