Normally we create 1:1 mapping per table-class.
Ex(Tables):
[users]
user_id - PK
name
[transactions]
user_id - FK
item_id
amount
Example mapping:
public class User
{
public string ID {get; set;}
public string Name {get; set;}
}
public class Transaction
{
public string UserID {get; set;}
public string ItemID {get; set;}
public Decimal Amount {get; set;}
}
But due to optimization concern and sometimes there are operations needed to be done while querying for results; we usually use stored procedures that returns result from multiple tables.
If we use the example above; how can we call a procedure that returns results from the joined tables? Is it possible without creating a new class and binding just for the sake of this combined records?
Thanks!
It is possible to use a stored procedure in this case, using a mapping construct like the following:
This example assumes that Transactions is mapped as a bag on the User class. You would use this query as follows from C#:
NHibernate documentation on usage of custom SQL queries is here.
Cheers, Gerke.