Page 1 of 2
OK you geeks

Posted:
Thu Jun 03, 2010 5:34 pm
by jimmydanger
How do you do an NHibernate inner join query? Should I use a subquery(DetachedCriteria), CreateCriteria or CreateAlias? Too many unhelpful examples when Googled. Here's the SQL:
select *
from contractdetails cd
inner join
contractheaders ch
on cd.contract_num = ch.contract_num
and cd.vendor_no = ch.vendor_no
and ch.chain_code = 'TA'
where
cd.item_no = '054064'
and cd.effective_price_date < '6/3/2010'
and cd.item_end_date > '6/3/2010'

Posted:
Thu Jun 03, 2010 5:38 pm
by ColorsFade
I'm not going to get any StackOverflow points for answering this here Jimmy...


Posted:
Thu Jun 03, 2010 5:39 pm
by jimmydanger
Fine, choose points over your buddies...

Posted:
Thu Jun 03, 2010 6:42 pm
by jimmydanger
Got it:
#region Contracts
public ContractDetail ActiveContractDetail()
{
ContractDetail contractDetail = SessionManager.GetSession().CreateCriteria(typeof(ContractDetail))
.CreateAlias("ContractHeader", "h")
.Add(Expression.Eq("Item", this))
.Add(Expression.Eq("h.chain_code", "TA"))
.Add(Expression.Le("effective_price_date", DateTime.Today))
.Add(Expression.Ge("item_end_date", DateTime.Today))
.UniqueResult<ContractDetail>();
return contractDetail;
}
#endregion

Posted:
Thu Jun 03, 2010 7:57 pm
by Chippy
I agree a good TA always has good food.
You're a very clever man Jimmy.

Posted:
Fri Jun 04, 2010 12:55 am
by gtZip
I as going to say CreateCriteria.
Really.
I swear.
But I dont know SQL


Posted:
Fri Jun 04, 2010 2:10 am
by jimmydanger
It's not really SQL, but you have to be able to write the query using T-SQL before transforming into an NHibernate query. The other part was creating a bag in the detail mapping file and a many-to-one relationship in the header mapping file or else the CreateAlias would not work.
ORMs are wonderful, they save writing a hundred lines of ADO code.

Posted:
Fri Jun 04, 2010 5:54 am
by gtZip
What is it? Delphi with SQL commands?

Posted:
Fri Jun 04, 2010 7:58 am
by Krul
Where did you learn of this alien teaching


Posted:
Fri Jun 04, 2010 12:18 pm
by jimmydanger
gtZip wrote:What is it? Delphi with SQL commands?
NHibernate is a port of Hibernate for the .Net platform. It's a popular Object Relational Mapping (ORM) technology. It allows you to refer to relational database tables as objects.
Funny you mention Delphi, I used Delphi in the 90's. It was better than Visual Basic until .Net came out.

Posted:
Fri Jun 04, 2010 12:37 pm
by philbymon
Bar: Initialize Contact
: Chatter up
: Buyer Drinks
: Offer/Ask For a Ride
Car: Miss shifter
: Grab Knee
: Wink lasciviously
Apartment: Add : More Drinks
: Initialize Intimate Contact
: Remove Fabric Covering
: Oscillate
: Add (Latex Wrapper)
: Add (More Intimate Contact)
: Add (Thrusters)
: Sleep
Next Morning: Send Her Out For Breakfast
: Add (Caring Facial Expression)
: Add (Ask For Phone Number)
: Add (Of Course I Respect You)
: GoTo : Work

Posted:
Fri Jun 04, 2010 1:07 pm
by jimmydanger
Nice algorithm Phil except for the GoTo at the end. That's a no no.

Posted:
Fri Jun 04, 2010 2:36 pm
by ColorsFade
Now, Jimmy, just save yourself some additional trouble and start using FluentNHibernate for configuration...

Posted:
Fri Jun 04, 2010 2:45 pm
by Tronix
I don't know what all this means, so it must be for the devil, and evil.
now where did I put that damned pitchfork again?