in

CodeSmith Community

Your Code. Your Way. Faster!

Business Object from a Stored Procedure ResultSet

Last post 02-27-2008 9:01 PM by ChristianPena. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 07-13-2004 4:03 PM

    • vermeeca
    • Top 500 Contributor
    • Joined on 07-13-2004
    • Posts 11
    • Points 380

    Business Object from a Stored Procedure ResultSet

    Hello,
     
    Haven't seen this posted before, but I apologize if someone's already uploaded this.  Here's a modified version of the BusinessObject template that's installed by default with CodeSmith.  This version generates the business object from the CommandRestultsSchema of a stored procedure, rather than a database table.
     
     
    Thanks,
    Craig
    • Post Points: 95
  • 10-18-2005 8:41 PM In reply to

    • spmoran
    • Not Ranked
    • Joined on 10-18-2005
    • Posts 1
    • Points 35

    RE: Business Object from a Stored Procedure ResultSet

    Hello. I see that this template leaves off the first column of each resultset. Has anyone else mentioned this? Is there a fix in place? Ok, and while I'm being a pest, is there a VB.Net version?
     
    Thanks so much.
     
    Sean
    • Post Points: 35
  • 11-16-2006 3:26 AM In reply to

    • bkar81
    • Top 500 Contributor
    • Joined on 11-16-2006
    • Posts 11
    • Points 110

    Re: Business Object from a Stored Procedure ResultSet

    Hi dude,

    This is what I have been looking for. Thank you very much.

    By the way, have you corrected the template - ref: spmoran

    Karthikeyan
    • Post Points: 5
  • 11-16-2006 8:38 AM In reply to

    • vermeeca
    • Top 500 Contributor
    • Joined on 07-13-2004
    • Posts 11
    • Points 380

    Re: RE: Business Object from a Stored Procedure ResultSet

    Thanks for the feedback, and the bug fix.  I've updated the original post with a fixed version of the template that doesn't leave off the first column.

    As far as a VB.NET version, sorry, you'll either need to do that yourself or find someone else to do it :)

    • Post Points: 35
  • 11-17-2006 1:15 AM In reply to

    • bkar81
    • Top 500 Contributor
    • Joined on 11-16-2006
    • Posts 11
    • Points 110

    Re: Business Object from a Stored Procedure ResultSet

    Hi vermeeca,

    Please reply me for the thread i have created

    "Creating Entities from Custom Stored procedures - Help Needed" -> http://community.codesmithtools.com/forums/permalink/20010/20010/ShowThread.aspx#20010

    I am looking for a solution. Thank you.

    Karthikeyan
    • Post Points: 5
  • 11-17-2006 12:07 PM In reply to

    • Khaos
    • Top 75 Contributor
    • Joined on 06-03-2005
    • CodeSmith Padawan
    • Posts 58
    • Points 886

    Re: Business Object from a Stored Procedure ResultSet

    At the risk of sounding like a total idiot, how do you consume the output?

     Thanks,

    Joe Johnston
    • Post Points: 35
  • 11-17-2006 12:11 PM In reply to

    • vermeeca
    • Top 500 Contributor
    • Joined on 07-13-2004
    • Posts 11
    • Points 380

    Re: Business Object from a Stored Procedure ResultSet

    If you execute the template inside CodeSmith Explorer, you can copy and paste the generated code into a new cs file.  That's one way, at least.  There's a Visual Studio add-in, too, but I haven't looked at that since way back in the CodeSmith 2.6 release, so it probably has changed quite a bit.
    • Post Points: 35
  • 11-17-2006 1:12 PM In reply to

    • Khaos
    • Top 75 Contributor
    • Joined on 06-03-2005
    • CodeSmith Padawan
    • Posts 58
    • Points 886

    Tongue Tied [:S] Re: Business Object from a Stored Procedure ResultSet

    I have it in a .cs now how is it consumed?  How do you wrap this up to be used by a data consumer.  I know this is a horribly simple question if you deal with this type of provider all the time but I don't know how to do it. <weak smile> 

     My humble thanks in advance,

    Joe Johnston
    • Post Points: 35
  • 11-17-2006 1:23 PM In reply to

    • vermeeca
    • Top 500 Contributor
    • Joined on 07-13-2004
    • Posts 11
    • Points 380

    Re: Business Object from a Stored Procedure ResultSet

    Ah, you're wanting to know how to use the class from within an application, then?  Am I understanding that right?

     I'll assume that you know how to use ADO.NET to call the stored procedure and get the results in a SqlDataReader.  If not, trying checking out the following links, depending on which version of .NET you're using:

    .NET 1.1 : http://msdn.microsoft.com/data/prev/ref/adonet/default.aspx

    .NET 2.0 : http://msdn.microsoft.com/data/ref/adonet/default.aspx

     Once you have the SqlDataReader, you just create an instance of the class you generated from the template, passing the SqlDataReader as a parameter into the constructor of the class.

     HTH.

     

    • Post Points: 35
  • 11-20-2006 4:12 PM In reply to

    • Khaos
    • Top 75 Contributor
    • Joined on 06-03-2005
    • CodeSmith Padawan
    • Posts 58
    • Points 886

    Re: Business Object from a Stored Procedure ResultSet

    like so?  i believe i simply dont understand the usage.  I use readers, datasets etc.  I just can't get my head wrapped around the use of the output.  It seems like its a structure for a single row...

            SqlService sql = new SqlService();
            sql.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
            SqlDataReader myReader = sql.ExecuteSPReader("sp_Blah"); // we have records
            while (myReader.Read())
            {System.Diagnostics.Debug.WriteLine(myReader.GetString(myReader.GetOrdinal("BlahField")));}

           ds_GetAction MyEx = new ds_GetAction(myReader); // ds_GetAction is the output class from Code Smith
            myReader.Close();

    -thanks for your patience,

    Joe Johnston
    • Post Points: 35
  • 11-21-2006 7:55 AM In reply to

    • vermeeca
    • Top 500 Contributor
    • Joined on 07-13-2004
    • Posts 11
    • Points 380

    Re: Business Object from a Stored Procedure ResultSet

    Actually, you'll want to instantiate the class within the loop, so that you get an instance of the class for each row in the SqlDataReader like so :

            SqlService sql = new SqlService();
            sql.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
            using(SqlDataReader myReader = sql.ExecuteSPReader("sp_Blah")) // we have records

            {
                 while (myReader.Read())
                 {

                          System.Diagnostics.Debug.WriteLine(myReader.GetString(myReader.GetOrdinal("BlahField")));

                         ds_GetAction MyEx = new ds_GetAction(myReader); // ds_GetAction is the output class from Code Smith

                 }

            }

     

    • Post Points: 35
  • 02-27-2008 9:01 PM In reply to

    Re: Business Object from a Stored Procedure ResultSet

    Thank you for this template. I was looking for precisely this and you provided it.

     

    Cheers,

     

    Christian 

    • Post Points: 5
Page 1 of 1 (12 items)
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems