0

I have to join a table TransactionDeclaration(Id,...) with a parametric function fp_Transaction_ACL(userId) which returns (TransactionDeclarationId,AccessRightId). The join must be an inner join.

I have done the following mapping using Fluent NHibernate:

    public TransactionDeclarationMap()
    {
        this.Id(transactionDeclaration => transactionDeclaration.Id);                   
        this.Join(
            "fp_TransactionDeclaration_ACL(:AclFilter.userId)",
            join =>
            {
                join.KeyColumn("TransactionDeclarationId");
                join.Map(transactionDeclaration => transactionDeclaration.AccessRight, "AccessRightType").CustomType
                    <AccessRight>().Generated.Always().ReadOnly();
                join.Inverse();
                join.Fetch.Join();
            });
     }

Since the function must not be inserted or updated, I have added the 'join.Inverse()' as explained here :

Nhibernate/hibernate Avoid Insert in joined table or view

But when I add this inverse, the join becomes a left outer join which is not ok for my use case. I need an inner join to filter records of the table 'TransactionDeclaration' not returned by the function.

How can I get an inner join ? Or is there an alternative to the 'Inverse' to avoid inserting in the function ?

Community
  • 1
  • 1
Thierry
  • 133
  • 1
  • 3
  • 12

1 Answers1

0

I don't know how to do it in Fluent, but you'll have to specify somewhere that the key where you're joining on, is not nullable.

Something like this, perhaps:

public TransactionDeclarationMap()
{
    this.Id(transactionDeclaration => transactionDeclaration.Id);                   
    this.Join(
        "fp_TransactionDeclaration_ACL(:AclFilter.userId)",
        join =>
        {
            join.KeyColumn("TransactionDeclarationId");
            join.Map(transactionDeclaration => transactionDeclaration.AccessRight, "AccessRightType").CustomType
                <AccessRight>().Generated.Always().ReadOnly();
            join.Inverse();
            join.SetAttribute ("optional", false);
            join.Fetch.Join();
        });
 }

click for more info.

Frederik Gheysels
  • 56,135
  • 11
  • 101
  • 154
  • I have tried "join.Not.Optional();" but this does not change anything. I still get a left outer join. – Thierry Sep 18 '12 at 06:29