This is a MUSIC forum. Irrelevant or disrespectful posts/topics will be removed by Admin. Please report any forum spam or inappropriate posts HERE.

All users can post to this forum on general music topics.

Moderators: bandmixmod1, jimmy990, spikedace

#113383 by jimmydanger
Thu Jun 03, 2010 5:34 pm
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'

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

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

#113391 by jimmydanger
Thu Jun 03, 2010 6:42 pm
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

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

#113420 by gtZip
Fri Jun 04, 2010 12:55 am
I as going to say CreateCriteria.
Really.
I swear.

But I dont know SQL 8)

#113424 by jimmydanger
Fri Jun 04, 2010 2:10 am
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.

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

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

#113443 by jimmydanger
Fri Jun 04, 2010 12:18 pm
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.

#113445 by philbymon
Fri Jun 04, 2010 12:37 pm
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

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

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

#113464 by Tronix
Fri Jun 04, 2010 2:45 pm
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?

Who is online

Users browsing this forum: No registered users and 2 guests