Database error 4104: The multi-part identifier could not be bound

If I use the alias of Query.From(), I sometimes get the exception, e.g.

Database error 4104: The multi-part identifier "Org.UID_Org" could not be bound.

The simpliest example is this one-liner

session.Source().GetCollection(Query.From("Org", "o").Select("UID_Org"), EntityCollectionLoadType.Slim);

"Sometimes" here means it depends on the permission set. If I'm logged into OI with my dev-user, it works, if I use other users it won't work.

The full exception message is

Error during execution of statement: select o.UID_Org, xxxSelect.XGroupBitPattern as XSelectGroupBitPattern, xxxSelect.XGroupMask as XSelectGroupMask from Org o join
    (
        select sum(distinct(x.XGroupBitPattern)) as XGroupBitPattern, 0x80000000020000000000001000800000000020 as XGroupMask, XXPrimaryKey1
            from(
                select 28 as XGroupBitPattern, UID_Org as XXPrimaryKey1 from Org
                union all
                select 1 as XGroupBitPattern, UID_Org as XXPrimaryKey1 from Org where (UID_Org in (select c.UID_Org from dbo.QER_FTHelperHeadOrgChildren ('a69ccae8-38cc-4621-bfdb-6bed6a91858f') c) or UID_Org in (select c.UID_ParentOrg from dbo.QER_FTHelperHeadOrgParents ('a69ccae8-38cc-4621-bfdb-6bed6a91858f') c))
                union all
                select 2 as XGroupBitPattern, UID_Org as XXPrimaryKey1 from Org where (UID_Org in (select UID_Org from Person where UID_Person = 'a69ccae8-38cc-4621-bfdb-6bed6a91858f') Or UID_Org in (select UID_Org from PersonInOrg where UID_Person = 'a69ccae8-38cc-4621-bfdb-6bed6a91858f'))
            ) x
        group by XXPrimaryKey1
    ) xxxSelect on xxxSelect.XXPrimaryKey1 = Org.UID_Org

Seems, like the alias is not used inside the inserted groupbitpattern-block - that should be o.UID_Org at the end.

So I think, Query.From(tableName, alias) is broken at the moment.

My questions are

  • what is the underlying error here (what differences between my user and the other users leads to this error.. Sounds like DialogGroup.GroupBitPattern but I try to understand the problem thoroughly)
  • are there more pitfalls (= "extensions" to the queries depending on the executing user)
  • since this query (and also more complex ones) doesn't use the added columns at all, I wonder if there's some magic in behind (if a column is named XSelectGroupBitPattern, then something special is executed?). If so - which names are reserved for such behavior?
  • ok, since you only allow a single predefined entity model to return from IEntitySource.Get+-commands, the last question is just for my personal interest Slight smile

  • The underlying error or the SQL you are seeing is part of the permission layer. And yes, the rights clause does not yet take into account the alias assigned from outside. We have taken VPR#35495 for this. The current workaround would be to avoid the alias as it is not necessary for your use-case.

    In regards to your questions:

    • The difference between your users is, that users that are failing have a permission where-clause set for the table Org.
    • There are no other extensions besides the rights clause from the permission layer.
    • The selected columns (UID_Org in your case) will be used. They are part of the user permission generation process in the object layer.