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