CodeSmith Community
Your Code. Your Way. Faster!

Custom SQL Stored procedures Not Showing Up

Latest post 09-06-2006 1:53 AM by hauszerm. 15 replies.
  • 03-21-2006 12:24 PM

    • needbrew
    • Top 150 Contributor
    • Joined on 03-20-2006
    • Posts 38
    • Points 1,180

    Custom SQL Stored procedures Not Showing Up

    Hi All,

     

    I have created a custom stored procedure called [dbo].[usp_cust_Deal_GetByAll]   The procedure takes no paramters and returns a join of some tables attached to the deal table.  I have set the customProcedureStartsWith = "{1}cust_{0}_" and have the IncludeCustoms = True.  My procedure prefix = "usp_".  I am using the nightly build from 03/21/2006.

     

    Thanks in advance

    • Post Points: 35
  • 03-21-2006 10:11 PM In reply to

    Re: Custom SQL Stored procedures Not Showing Up

    I could not recreate this issue.  I setup a procedure with the exact same format as you, but used it against the Orders table in the Northwind Database, and it generated the method out just fine for me.  (See Below)

    One thing to note, Codesmith will cache the schema once it initially reads it.  So if you create a procedure, or modify the schema in any way, you have to either, A) recompile the NetTiers.cst template, so that it will flush the cache, or B) close and re-open Codesmith. 

    Please correct me if I'm wrong anyone.

    SqlOrdersProviderBase.cs
            #region "usp_cust_Orders_GetByAny"
                        
            /// <summary>
            ///    This method wrap the 'usp_cust_Orders_GetByAny' stored procedure. 
            /// </summary>    
            /// <param name="var1"> A <c>System.Int32?</c> instance.</param>
            /// <param name="start">Row number at which to start reading.</param>
            /// <param name="pageLength">Number of rows to return.</param>
            /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
            /// <remark>This method is generate from a stored procedure.</remark>
            /// <returns>A <see cref="DataSet"/> instance.</returns>
            public override DataSet GetByAny(TransactionManager transactionManager, int start, int pageLength , ref System.Int32? var1)
            {
                SqlDatabase database = new SqlDatabase(this._connectionString);
                DbCommand commandWrapper = database.GetStoredProcCommand("usp_cust_Orders_GetByAny");
                
        
                    database.AddParameter(commandWrapper, "@Var1", DbType.Int32, ParameterDirection.InputOutput, "", DataRowVersion.Current,var1);
                
                DataSet ds = null;
                
                if (transactionManager != null)
                {    
                    ds = database.ExecuteDataSet(commandWrapper, transactionManager.TransactionObject);
                }
                else
                {
                    ds = database.ExecuteDataSet(commandWrapper);
                }
                
                var1 =  Utility.GetParameterValue<System.Int32?>(commandWrapper.Parameters["@Var1"]);
    
                
                return ds;    
            }
            #endregion
    
    

    Here's the relevant info in my Property Set.
    <propertySet>
        <property name="DataAccessLayerNameSpace">DataAccessLayer</property>
        <property name="UnitTestsNameSpace">UnitTests</property>
        <property name="ExecuteSql">False</property>
        <property name="SQLFolderName">SQL</property>
        <property name="IncludeUnitTest">False</property>
        <property name="IncludeCustoms">True</property>
        <property name="CustomNonMatchingReturnType">DataSet</property>
        <property name="CustomProcedureStartsWith">{1}cust_{0}_</property>
        <property name="IncludeDrop">True</property>
        <property name="IncludeInsert">True</property>
        <property name="IncludeUpdate">True</property>
        <property name="IncludeSave">True</property>
        <property name="IncludeDelete">True</property>
        <property name="IncludeGet">True</property>
        <property name="IncludeGetList">True</property>
        <property name="IncludeGetListByFK">True</property>
        <property name="IncludeGetListByIX">True</property>
        <property name="IncludeFind">True</property>
        <property name="IncludeManyToMany">True</property>
        <property name="IncludeRelations">True</property>
        <property name="IsolationLevel">None</property>
        <property name="InsertSuffix">_Insert</property>
        <property name="UpdateSuffix">_Update</property>
        <property name="DeleteSuffix">_Delete</property>
        <property name="SelectSuffix">_Get</property>
        <property name="SelectAllSuffix">_List</property>
        <property name="FindSuffix">_Find</property>
        <property name="RetryEnabled">True</property>
        <property name="RetryMaxAttempts">3</property>
        <property name="RetrySleepTime">1000</property>
        <property name="GenerateWebservice">False</property>
        <property name="ViewReport">True</property>
        <property name="GenerateWebAdmin">False</property>
        <property name="WebAdminOutputPath">my path</property>
        <property name="GenerateWebLibrary">True</property>
        <property name="OutputDirectory">D:\NetTiersProject\SubmittedWork\TestProcs</property>
        <property name="SourceTables">
            <connectionString>Data Source=(local);Initial Catalog=Northwind;Integrated Security=true;Connection Timeout=1;</connectionString>
            <providerType>SchemaExplorer.SqlSchemaProvider,SchemaExplorer.SqlSchemaProvider</providerType>
            <tableList>... </tableList>
         <property name="WebServiceOutputPath" />
        <property name="NameSpace">NorthwindProcs</property>
        <property name="BusinessLogicLayerNameSpace">Entities</property>
        <property name="CompanyName">NetTiers</property>
        <property name="CompanyURL">www.nettiers.com</property>
        <property name="EntireDatabase">False</property>
        <property name="SourceDatabase">
            <connectionString>Data Source=(local);Initial Catalog=Northwind;Integrated Security=true;Connection Timeout=1;</connectionString>
            <providerType>SchemaExplorer.SqlSchemaProvider,SchemaExplorer.SqlSchemaProvider</providerType>
        </property>
        <property name="RetrySleepStyle">Constant</property>
        <property name="WebServiceUrl" />
        <property name="StrippedTablePrefixes">tbl;tbl_</property>
        <property name="EntityFormat">{0}</property>
        <property name="CollectionFormat">{0}Collection</property>
        <property name="GenericViewFormat">VList&lt;{0}&gt;</property>
        <property name="GenericListFormat">TList&lt;{0}&gt;</property>
        <property name="ProviderFormat">{0}Provider</property>
        <property name="InterfaceFormat">I{0}</property>
        <property name="BaseClassFormat">{0}Base</property>
        <property name="EnumFormat">{0}List</property>
        <property name="ManyToManyFormat">{0}From{1}</property>
        <property name="AliasFilePath" />
        <property name="ProcedurePrefix">usp_</property>
    </propertySet>
    

    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 35
  • 04-07-2006 4:27 PM In reply to

    Re: Custom SQL Stored procedures Not Showing Up

    I was able to generate the custom methods from the custom stored proc. However, when I tried to compile, it errored out with "no suitable method found to override". Is that a bug or do I have to do some maual coding?

    -Neal

     

    • Post Points: 35
  • 04-07-2006 5:01 PM In reply to

    Re: Custom SQL Stored procedures Not Showing Up

    This situation has been coming up lots lately.  I just haven't found a way to reproduce it locally with the procedures and Codesmith version that I use to correct the issue.  Can you provide some more info on the procedure, cs version, originating table so that I can reconstruct this scenario.

    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 35
  • 04-07-2006 5:19 PM In reply to

    Re: Custom SQL Stored procedures Not Showing Up

    I think I found the problem. This has to do with using the ProcedurePrefix. If I do not use this option, it compiles fine. If I do use it, it does not generate all the required methods.
    • Post Points: 35
  • 04-07-2006 6:33 PM In reply to

    Re: Custom SQL Stored procedures Not Showing Up

    Smile [:)]  This is something to work with.  Thanks! 

    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 5
  • 04-09-2006 1:18 AM In reply to

    Re: Custom SQL Stored procedures Not Showing Up

    This has been fixed in SVN Revision 116.

    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 35
  • 04-09-2006 9:40 AM In reply to

    Re: Custom SQL Stored procedures Not Showing Up

    Cool! I am glad I was able to help in some way. When is SVN116 coming out? Where can I get this?
    • Post Points: 35
  • 04-09-2006 10:38 AM In reply to

    Re: Custom SQL Stored procedures Not Showing Up

    Hi, it will be part of the next nightly build.  Or, you can get it using an SVN client, we recommend TortoiseSVN.

    Here is a link that describes how to get the latest from SVN, so that you don't have to wait for the next nightly build.

    http://community.codesmithtools.com/forums/permalink/10866/10834/ShowThread.aspx#10834

    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 35
  • 09-05-2006 9:09 AM In reply to

    • hauszerm
    • Top 500 Contributor
    • Joined on 06-19-2006
    • Graz, Austria
    • Posts 12
    • Points 300

    Re: Custom SQL Stored procedures Not Showing Up

    Hi, I have problems to create code fpr my custom procedures

    The procedure is very simple an follows the naming convention of .nettiers 

    The table is called app_translations and this is the procedure

    CREATE        PROCEDURE _app_translations_ListColumnNames
    (
     @table NVARCHAR(50),
     @language NVARCHAR(5) = 'EN'
    )
    AS
      IF EXISTS(SELECT 1 FROM sysobjects WHERE name= @table)
      BEGIN
        DECLARE @SQL_STMT VARCHAR(8000)
      DECLARE @name varchar(255)
       IF (@language <> '')
      BEGIN
       -- select @table
       SET @name =
    'a.ANAME_'+@language 
       -- SET @SQL_STMT =  'SELECT a.ANAME, "
    '+@name+'" = (CASE WHEN ' + @name + ' IS NULL THEN a.ANAME_EN ELSE ' + @name + ' END), ATYPE FROM attributes a,  entities e
       SET @SQL_STMT =  'SELECT a.ANAME, ALIAS = (CASE WHEN ' + @name + ' IS NULL THEN a.ANAME_EN ELSE ' + @name + ' END), ATYPE FROM attributes a,  entities e
        WHERE e.t_id = a.t_id
        AND e.dbtname like ''' + @table + ''''
       -- print @sql_stmt
       EXEC(@SQL_STMT)
      END
     END

    I am working with the templates .netTiers 2.0.0.0 beta 2

    This are the relevant properties

      <property name="IncludeCustoms">True</property>
      <property name="CustomNonMatchingReturnType">DataSet</property>
      <property name="CustomProcedureStartsWith">_{0}_</property>
      <property name="ProcedurePrefix" />

     

    I have done a lot of trials but I never found the generated code in the file

    SqlApp_translationsProviderBase.generated.cs    

      #region Custom Methods
     
      #endregion


    where i supposed to find the generated code;

    the section above was empty

    Now I have no idea what to do and request help 

    best reagards Michael

    • Post Points: 35
  • 09-05-2006 9:30 AM In reply to

    Re: Custom SQL Stored procedures Not Showing Up

    Hi hauszerm,

    Unfortunately when Codesmith is doing discovery on stored procedures, it does so using SET FMTONLY ON, which SQL Server will attempt to run the procedure in read only mode, and with limited rights.  So, it can't execute dynamic queries like that or create temp tables.

    You can create a check to see if all the params are NULL, if they are, then you can send a skelaton of the resultset you want to be used.

    IF @table IS Null AND @Language IS NULL
    BEGIN
      SELECT a.ANAME, ALIAS = (CASE WHEN cast('' as varchar(255)) IS NULL THEN a.ANAME_EN ELSE cast('' as varchar(255)) END), ATYPE
    FROM attributes a,  entities e
    where 1=0
    Return 0
    END

    IF both params can be NULL, then you can check to see if USER_NAME() is NULL

    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 60
  • 09-05-2006 11:27 AM In reply to

    • hauszerm
    • Top 500 Contributor
    • Joined on 06-19-2006
    • Graz, Austria
    • Posts 12
    • Points 300

    Re: Custom SQL Stored procedures Not Showing Up

    Hi,

    I made the changes in my procedure according to your hints but  I couldn't generate any code.

    Maybe I didn't understand the whole meaning of your explanation.

    Only for tests, I wrote a very simple procedure

    ALTER         PROCEDURE _app_translations_ListColumnNames
    (
     @table NVARCHAR(50),
     @language NVARCHAR(5) = 'EN'
    )
    AS
      SELECT a.ANAME, ALIAS =  a.ANAME_EN , a.ATYPE
      FROM attributes a,  entities e
      WHERE e.t_id = a.t_id
      AND e.dbtname like  @table

    but CodeSmith didn't generate any code for this custom stored procedure.

    What are the preconditions, that CodeSmith will discover a stored procedure ?
    Is  there an alternative method, to "mark" stored procedures, to get discovered ?

    I would like to use .netTiers with CodeSmith for building addons on an existing project with a lot of existing stored procedures buildng the the inteface to the  "business logic". I don't want to rewrite running code, but I want to create future enhancements supported by Tools like CodeSmith.

    Best Regards Michael

     

    • Post Points: 65
  • 09-05-2006 11:48 AM In reply to

    Re: Custom SQL Stored procedures Not Showing Up

    Hi hauszerm,

    Is app_translations one of the tables in your database? Remember the CustomProcedureStarts parameter should be in the _{0}_ format.

     

    • Post Points: 5
  • 09-05-2006 11:52 AM In reply to

    • Rippo
    • Top 75 Contributor
    • Joined on 05-06-2005
    • UK
    • Posts 64
    • Points 1,530

    Re: Custom SQL Stored procedures Not Showing Up

    Did you change?
    <property name="CustomProcedureStartsWith">_{0}_</property>

    Should it not be
    <property name="CustomProcedureStartsWith">{1}_{0}_</property>

    That is if your tablename is "translations"

    "CustomProcedureStartsWith: include custom stored procedures, this is the pattern that NetTiers will look for your custom stored procedures to start with. A string format will be used to match the beginning of the procedure pattern. So, {0}=TableName, {1}=ProcedurePrefix(See Property Below). By default NetTiers will look at tables that starts with '_{0}_', which means it will detect the procedure _TableName_GetByBirthdate and generate the necessary plumbing to wrap your custom stored procedure. Your new method can be accessed by  DataRepository.TableNameProvider.GetByBirthdate(); "

    Richard Wilde wildesoft.net

    • Post Points: 35
  • 09-05-2006 1:57 PM In reply to

    • hauszerm
    • Top 500 Contributor
    • Joined on 06-19-2006
    • Graz, Austria
    • Posts 12
    • Points 300

    Re: Custom SQL Stored procedures Not Showing Up

    Hi,

    I did not change the property, it is

    <property name="CustomProcedureStartsWith">_{0}_</property>

    The tablename  'app_translations' and I am confident the underscore in the tablename will not cause troubles for CodeSmith to discover the custom stored procedure

    Michael

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