i'd like to retrieve the value of the extended property of my SSDT tables and columns so i can use it for some model generation stuff i'm working on using T4.
I can't find any examples of this done online, has anyone else done this?
These are the extended properties you can add with the following:
GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value =
N'somepropertytext', @level0type = N'SCHEMA', @level0name = N'dbo',
@level1type = N'TABLE', @level1name = N'table_name', @level2type =
N'COLUMN', @level2name = N'column_name';
in my T4 template where i'm loading the column info I have this:
var property = column.GetProperty<string>(???);
I'm not sure what goes in the ??? part to get this extended property information. Any ideas?
I am able to get other properties about the column like nullable, precision, etc.
MS doc on this is a bit... lacking.
The extended property isn't a property of the column, it's the other way around, i.e. the column is what the extended property refers to!
var propertyName = column.GetReferencing()
.Where(x=> x.ObjectType.Name == "ExtendedProperty").First()
.Name.ToString();
var propertyValue = column.GetReferencing()
.Where(x=> x.ObjectType.Name == "ExtendedProperty").First()
.GetProperty(ExtendedProperty.Value);
Extending this method-chaining mayhem to loop over all extended properties of the object is left as an exercise for the reader...