Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Really frustrated with this one - and it really seems a very simple issue :-/

Im using NHibernate to execute a SQL statement that first inserts a new row, then inserts a row in a different table based on the id that the first insert generated.

The SQL for it works fine:
 INSERT INTO messages(MessageSubject,MessageText,MessageSenderTribeID,MessageSentTime,MessageHasAttachments) 
VALUES('subject', 'text',204948, 2009, 0);
SET @last=LAST_INSERT_ID();
INSERT INTO messagelinks(MessageID,MessageReceiverNodeID,SendMethodID)
VALUES(@last, 204948,3);
SELECT * FROM messages WHERE Messages.MessageID = @last;

However when i do this:

var session = NHibernateHelper.GetCurrentSession();
                IQuery query = session.CreateSQLQuery(that sql here).AddEntity(typeof(messages));



                IList<messages> messageRes = query.List<messages>();

It throws an error saying not all named parameters have been set?

I dont need any named parameters or anything - just need nhibernate to execute the sql. Please help, thanks :)
Posted
Updated 2-Sep-10 11:08am
v2

1 solution

ok why dont you make it a stored procedure and then pass the parameters into it, Im sure it will resolve the problem with the 'no setting of parameters'..
 
Share this answer
 
Comments
Matt Cavanagh 4-Sep-10 6:17am    
I'm an idiot for not thinking of that, thanks :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900