microsoft / DACExtensions

DACExtensions contains samples that extend Data-Tier Applications using DacFx. These samples include deployment contributors and static code analysis rules that can be used with Visual Studio as well as examples of how to use the DacFx public mode
MIT License
125 stars 41 forks source link

Add unresolved elemements plus metadata properties #2

Closed lonnybastien closed 9 years ago

lonnybastien commented 9 years ago

Refactor to support unresolved elements. This requires changing all calls from GetReferenced to GetReferencedRelationshipInstances for Peer and Hierarchical relationships. With methods now returning unresolved elements, a new Reference sub class for each Model type is defined. The reference sub types adapts a ModelRelationshipInstance instead of a TSQLObject. Adapting a ModelRelationshipInstance instead of a TSQLObject allows the name of referenced elements to be exposed even if the element is unresolved. It also allows exposing the metadata on relationships (Such as Ascending on the Index.Columns relationship).

For each relationship that has metadata, a new sub type is defined with the metadata properties. This results in the Index.Columns relationship returning an IEnumerable where IndexColumnsReference derives from TSQLColumnReference which in-turn derives from TSQLColum. Metadata properties on TSQLObjecs are now exposed. One example of this is TSQLColumn now exposes a ColumnType property which defines if it is a Column, ComputedColumn or ColumnSet. NOTE: In order to facilitate unresolved references, a few edge cases arose. For relationships that returned marker interfaces like ISqlObjectAuthorizer, there was no concrete type known at generation time to instantiate. To work around this issue, a new optional attribute was added to the modelmetadata.xml: UnresolvedReturnType. The UnresolvedReturnType attribute defines the type to instantiate when an unresolved element is found so the return type will still implement the type defined in the ReturnType attribute. This pattern is a little unconventional, however, to enforce the strongly typed returns values of relationships these “Unresolved” types needed to be created to bridge the gap between the strongly typed API and the unresolved nature of the model.