Output Parameter mapping

Oct 12, 2007 at 2:46 PM

What is the proper way to retrieve the output paremeter of a stored procedure when using the Repository Factory "Insert" method?

The default created return type of the generated method is "void", and in my particular case, I need it to be "int". The INSERT stored procedure returns the IDENTITY row from the table it's inserting into as an output parameter. I would think that the Reposity Factory wizard would have a way to automate that, but I've poked around online to figure it out with not a lot of luck.


Austin, TX
Oct 12, 2007 at 3:19 PM
The Repository Factory does take care of this for you. The insert stored procedure does grab the Identity after the insert and return it as a parameter.

The property of the business class that has been mapped to the identity column is then set to the identity value as you can see in the base Repository Class:

public void Add(IInsertFactory<TDomainObject> insertFactory, TDomainObject domainObj)
    using (DbCommand command = insertFactory.ConstructInsertCommand(this.db, domainObj))
        insertFactory.SetNewID(this.db, command, domainObj);

the insertFactory.SetNewID method grabs the parameter and assigns it to the business object property mapped to the identity column.

This is properly encapsulating the functionality and you would never want it to return an "int". I recommend checking your code to make sure this is all happening.




David Hayden
Microsoft MVP C#
Nov 15, 2007 at 7:34 PM
David, and what about if mi stored procedures have more that one output paramater? I need to put them in my bussines object?

Best regards
Jan 2, 2008 at 2:06 AM

Can you provide sample code for get the returned id on the insert sp. I am trying GetParmeterValue and it is giving me an error, say the id does not exist. I then tried to put in a AddOutParmeter of the id and it said the I have to many parmeters.