CodeSmith Community
Your Code. Your Way. Faster!

Cannot access extended properties

Latest post 11-28-2007 11:27 AM by LewisBlackburn_CodeSmith. 2 replies.
  • 11-19-2007 12:34 PM

    Cannot access extended properties

    I have a CodeSmith template that loads a CommandSchema object based on a stored procedure in my DB and accesses the CommandResults[0] property to get the first (and only) result set of the SP.  This property gives me a CommandResultSchema object.  I can then iterate it's Columns collection and access information about the underlying DB column to create an XSD that will be used by a typed dataset.  This has worked great for me so far but I now have a need to add the default value for the column into the generated schema.  I have read many posts saying to access the ExtendedProperties property but in my scenario the extened properties are not being populated for the columns.  I have tried this for identity, default, and description and the schema never reads in those values.  Can anyone tell me why I am not getting the extended properties?  Here is pseudo-code:

    ---------------
    SQL Code
    ---------------

    --Create table with default value for LastUpdate column
    CREATE TABLE [dbo].[Location](
     [ID] [int] IDENTITY(1,1) NOT NULL,
     [LocationName] [varchar](50) NOT NULL,
     [SeatCount] [int] NOT NULL CONSTRAINT [DF_Location_SeatCount] DEFAULT (10)
    GO

    --Create SP
    CREATE PROCEDURE [dbo].[Location_SelectByID]
     @ID int
    AS
    SELECT ID, LocationName, SeatCount
    FROM Location
    WHERE ID = @ID
    GO


    ------------------------------
    CodeSmith template
    ------------------------------

    CommandSchemaCollection commandSchemas = new CommandSchemaCollection(SourceDatabase.Commands);
    CommandSchema commandSchema = commandSchemas[0];
    CommandResultSchema commandResultSchema = commandSchema.CommandResults[0];
    CommandResultColumnSchema columnSeatCount = commandResultSchema.Columns[2];


    --------
    Tests
    --------

    ?columnSeatCount.ExtendedProperties.Count
    Result: 0

    ?column.ExtendedProperties["CS_Default"].Value
    Result: 'column.ExtendedProperties["CS_Default"]' is null

    Filed under:
    • Post Points: 35
  • 11-21-2007 1:25 PM In reply to

    • pwelter34
    • Top 25 Contributor
    • Joined on 03-13-2003
    • Eden Prairie, MN
    • Posts 255
    • Points 749,885

    Re: Cannot access extended properties

     Which version of CodeSmith are you using?  In CodeSmith Studio, you can use the SchemaExplorer window to see what extended properties CodeSmith is getting.  Select a database object in SchemaExplorer.  In the property window, you'll see a property for ExtendedProperties.  Click the elipces and you'll see a grid of the extended properties of that db object.

     ~ Paul

    • Post Points: 35
  • 11-28-2007 11:27 AM In reply to

    Re: Cannot access extended properties

    Paul,

    Thanks for the reply.  I am using CodeSmith version 3.2.7.  When I view the properties of database objects in the schema explorer (either tables or stored procedures) I only see DateCreated, Description, FullName, Name, and Owner in the properties window.  If I drill down to the fields that are returned from the stored procedure I see AllowDBNull, DataType, Description, Name, NativeType, Precision, Scale, Size, and SystemType.

    Let me know if this info points you to any conclusions.

    Thanks

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