CodeSmith Community
Your Code. Your Way. Faster!

Creating Entities from Custom Stored procedures - Help Needed

Latest post 11-21-2006 11:45 PM by bkar81. 5 replies.
  • 11-17-2006 1:06 AM

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

    Creating Entities from Custom Stored procedures - Help Needed

    Hi,

    I want to generate entities for custom stored procedures along with the entities created from tables & views. I am having a cst file (Business Object from a Stored Procedure ResultSet) that will accept a single custom stored procedure as input, and generates the entities. The problem is, i want a property called SourceSPs like SourceTables in the basic template itself, which will accept the storedprocedures for which the entities has to be created. I think this feature is not available currently in .netTiers. If anybody could suggest me what to do, it would be very helpful.

    I changed the netTiers.cst file to accept the CSPs. But i dont know how to proceed further to generate the code & save the file etc... Please help me ASAP. Thank you.

    I dont know, whether this has been posted earlier or not. I am sorry if so.

    Karthikeyan
    • Post Points: 35
  • 11-17-2006 12:08 PM In reply to

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

    Re: Creating Entities from Custom Stored procedures - Help Needed

    Under the CodeSmith sample templates, check out the DBDocumenter\master.cst template.  It shows how to execute other templates and direct their output to a file.

    • Post Points: 35
  • 11-19-2006 10:56 PM In reply to

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

    Re: Creating Entities from Custom Stored procedures - Help Needed

    Thank you very much.

    I have created a cst to work with other cst, but need to learn a lot.

    I am having a doubt. Whats the difference between

    private CodeTemplate _mysubTemplate;
     [Browsable(false)]
     public CodeTemplate MySubTemplate
     {
      get
      {
       if (_mysubTemplate == null)
       {
        CodeTemplateCompiler compiler = new CodeTemplateCompiler("SubTemplate.cst");
        compiler.Compile();
        if (compiler.Errors.Count == 0)
         _mysubTemplate = compiler.CreateInstance();
        else
         for (int i = 0; i < compiler.Errors.Count; i++)
          Response.WriteLine(compiler.ErrorsIdea.ToString());
       }
       return _mysubTemplate;
      }
     }

    and

    <%@ Register Name="MySubTemplate" Template="SubTemplate.cst" MergeProperties="True" ExcludeProperties="IncludeMeta" %>

    as these two are serving the same.......

    Also I want to know whether there is any other code for OutputDirectory other than this, as i am feeling it to be very lengthy.

     private string _outputDirectory = String.Empty;

     [Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
     [CodeTemplateProperty(CodeTemplatePropertyOption.Optional)]
     [Category("Context")]
     [Description("The directory to output the results to.")]
     [DefaultValue("")]
     public string OutputDirectory
     {
      get
      {
       if (_outputDirectory.Length == 0)
       {
        return @"c:\NetTiers\Output";
       }
       else
       {
        return _outputDirectory;
       }
      }
      set
      {
       if (value.EndsWith("\\")) value = value.Substring(0, value.Length - 1);
       _outputDirectory = value;
      }
     }

    I am using these codes in overridden Render method 

    mySubTemplate.Render(Response);   
    Response.WriteLine("Finished");

    My subtemplate is executing. But i want to display "Finished" in the calling template. How to do it?

    Thanks in advance

    Karthikeyan
    • Post Points: 5
  • 11-20-2006 7:45 AM In reply to

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

    Re: Creating Entities from Custom Stored procedures - Help Needed

    Hi, I have created 2 CSTs, one driving the other. I want to create objects from multiple stored procedures. Hence in the first CST, i am having all the SPs & passing each SP to the other CST file. The second CST parses the SP & generate the code in the output window. I am saving the result of this 2nd CST file through the first calling CST file to a file in harddisk. I also want to display a message "Success" on rendering the SPs one by one, or in otherwords, i want to know how to workaround with the output window. I want to clear the output window when a particular action is done & have someother output in it. I dont know how to clear or flush the output window programatically.

    I want to save the output of the second CST file only when there is anything in the output window. If the output is NULL, it should not generate the file. So need to know the method or the way through which I can accomplish this job from the calling CST file.

    I am using CST2.RenderToFile method from the first CST file. But meanwhile i want to display a message in the first output window that the operation is success. Please help me to get me a solution.

    Thank you.

    Karthikeyan
    • Post Points: 35
  • 11-21-2006 8:01 AM In reply to

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

    Re: Creating Entities from Custom Stored procedures - Help Needed

    Sorry, I don't have an answer for either of your questions.  I've never tried clearing the template output (I doubt that CodeSmith was designed for that, actually).  I suppose you could still use RenderToFile and programmatically check the file size or something, if it came down to it.
    • Post Points: 35
  • 11-21-2006 11:45 PM In reply to

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

    Re: Creating Entities from Custom Stored procedures - Help Needed

    Thank you for your reply.

    I think, codesmith might have not thought about clearing the template output.

    I dont know why codesmith has not included "creating business objects from SPs" in their normal template itself.

    I have included my own code in NetTiers.cst file which will generate business objects from stored procedures. The output is working fine, creating files in the respective directories which I specify. But its not adding in the Solution created during the Run. Can u please tell me where I need to add the coding, so that the files which I generate are automatically added to the solution's corresponding project. So when compiling the solution, automatically my classes will also be present in the dlls created. I think you can get what I am trying to say.

    Thanks

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