Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8275087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:57:28+00:00 2026-06-08T07:57:28+00:00

I have two tables (Orders, Transactions) and a TransactionsOrders lookup table that just retains

  • 0

I have two tables (Orders, Transactions) and a TransactionsOrders lookup table that just retains an OrderId and TransactionsId columns.

There can be multiple transactions for an order if a transaction failed (n) times. And the Order object doesn’t have any knowledge of the transactions.

I believe I will need to use projections as I will need to return all the order properties as well as two properties from the Transactions table (Amount and TransactionDate) if a successful transaction record exists for that order. Below is the SQL that will generate the correct output.

   SELECT o.*, ct.TransactionDate, ct.Amount from Orders o
   LEFT OUTER JOIN 
     (SELECT * FROM CreditTransactionsOrders cto
          INNER JOIN CreditTransactions ct 
      ON ct.Id = cto.CreditTransactionId
      WHERE ct.Successful = 1) as ct 
   ON o.Id = ct.OrderId

I have attempted to try creating this QueryOver and projecting the properties I need from the Order object and Transaction object but can’t convert this SQL query properly.

The end results is that I need to return ALL orders, and I need to return the Amount and Date from the Transaction object IF a successful one exists for that Order. I am not really sure if I have to use aliases, but so far all my attempts have been unsuccessful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:57:29+00:00Added an answer on June 8, 2026 at 7:57 am

    First you have to rewrite your SQL to more NHibernate friendly state:

    SELECT o.*, ct.TransactionDate, ct.Amount from Orders o
      LEFT OUTER JOIN CreditTransactionsOrders cto 
        ON o.Id = cto.OrderId
      LEFT OUTER JOIN CreditTransactions ct 
        ON ct.Id = cto.CreditTransactionId AND ct.Successful = 1
    

    This SQL will produce the same results as your original query.

    In NHibernate additional criteria for join could be translated as with statement.

    So you could use overload accepting withClause argument. So, assuming you have Orders and CreditTransactions mapped as many-to-many. You should get following QueryOver.

    Order o = null;
    CreditTransaction ct = null;
    
    var orders = session.QueryOver(() => o)
        .Left.JoinAlias(x => x.Transactions, () => ct, () => ct.Successful == 1)
        .List<Order>();
    

    UPDATE

    As you have no reference from Order to Transaction, you should revert the join, so you could use right join to achieve this.

    Order o = null;
    CreditTransaction ct = null;
    
    var orders = session.QueryOver(() => ct)
        .Right.JoinAlias(x => x.Orders, () => o, () => ct.Successful == 1)
        .Select(
            x => x.TransactionDate,
            x => x.Amount,
            x => o.Id // other Order fields
        ).TransformUsing(Transformers.AliasToBean<TransactionsDto>())
        .List<TransactionsDto>();
    

    TransactionsDto class should contain all selected fields.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these two tables Orders and Employees Orders Table OrderID EmployeeID 1 1
I have two tables: orders and orders_items. Both sharing the field orderID. I want
I have two tables Orders(ID,ORDERDATE,DELIVERYDATE,GOODID,QUANTITY,COLLECTIONFROM,DELIVERYTO,NOTES) and ROLLINGSTOCK_ORDER(ORDERID,ROLLINGSTOCKID,DEPARTUREDATE,DELIVERYDATE,ROUTEID) i have created a trigger to update
I have two tables Orders table and customers table, both have customerid as common
I have two tables, orders and old_orders. Each table has some similar fields and
I have created two tables ORDERS and ORDERITEMS with the following constraint: alter table
I have these two tables: Table: ORDERS ID - NAME - DATA --------------------------------------------- 1
I have two tables orders and orderdetails table orders (PK = id, UNIQUE index
I have two tables in MySQL sales database: Orders table: CREATE TABLE salestest.`orders` (
I have two tables: orders: orderid customer_id amount 1 5 1 2 5 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.