If you’re lucky enough to be a BimlStudio user, you have access to the Biml Metadata feature! This feature allows you to build a Metadata model that fits your exacts needs which can then be browsed and used through a Metadata Instance using a dynamic object model.
As you probably still want to maintain your metadata outside of BimlStudio, we’ve build this little piece of code. It will ready your meta-Schema from a given SQL Database and build a Biml Metadata-Model from it. In a second step, it will also import the contents of your model into an instance:
Sofern Sie eine BimlStudio Lizenz besitzen, so steht Ihnen dort auch das Feature Biml Metadaten zur Verfügung. Dieses erlaubt es ein Metadaten-Modell anzulegen, welches genau Ihren Anforderungen entspricht. Die Inhalte können dann wiederum sehr einfach über eine Metadaten-Instanz sowie ein dynamisches Objekt-Modell abgefragt und genutzt werden.
Da Sie die Daten vermutlich dennoch weiterhin außerhalb von BimlStudio pflegen und warten wollen, haben wir diesen Quellcode geschrieben. Er liest das Schema “meta” aus einer vorgebenen Datenbank aus und leitet daraus das Metadaten-Modell ab. Im zweiten Schritt baut er noch eine Metadaten-Instanz mit den Werten aus den SQL Tabellen auf:
<#@ template language="VB" optionexplicit="False" #> <# connMetadata = "Data Source=.;Initial Catalog=BimlDemo_DerivedMetadata;Provider=SQLNCLI11;Integrated Security=SSPI;" Dim MetaConnection = SchemaManager.CreateConnectionNode("Meta", connMetadata) Dim MetaSchema = MetaConnection.ImportDB("meta",nothing,nothing)#> <Biml xmlns="http://schemas.varigence.com/biml.xsd"> <Metadata> <MetadataModel Name="MetaData"> <Entities> <# for each tbl in MetaSchema.TableNodes #> <Entity Name="<#= tbl.Name #>"> <Properties> <# for each col in tbl.Columns.Where(Function(c) c.Name.ToUpper <> "NAME" and c.IsUsedInPrimaryKey=false and c.GetType() <> GetType(Varigence.Languages.Biml.Table.AstTableColumnTableReferenceNode)) #> <Property Name="<#= col.Name #>" DataType="String"/> <# next #> </Properties> <Relationships> <# for each fk in tbl.Columns.OfType(Of AstTableColumnTableReferenceNode) #> <Relationship Name="<#= fk.ForeignTable #>" Cardinality="ManyToOne" EntityName="<#= fk.ForeignTable #>"></Relationship> <# next #> </Relationships> </Entity> <# next #> </Entities> </MetadataModel> <MetadataInstance Name="MetadataInstance" MetadataModelName="MetaData"> <Entities> <# for each tbl in MetaSchema.TableNodes #> <Entity Name="<#= tbl.Name #>" MetadataModelEntityName="MetaData.<#= tbl.Name #>"> <DataItems> <# for each DatRow in ExternalDataAccess.GetDataTable(connMetadata,"select * from [meta].[" & tbl.Name & "]").Rows #> <# if tbl.Columns.Where(Function(c) c.IsUsedInPrimaryKey=true).Any then#> <DataItem Name="<#= DatRow(tbl.Columns.Where(Function(c) c.IsUsedInPrimaryKey=true).First().Name) #>"> <# else #> <DataItem Name="<#= DatRow(0) #>"> <# end if #> <Properties> <# for each col in tbl.Columns.Where(Function(c) c.Name.ToUpper <> "NAME" and c.IsUsedInPrimaryKey=false and c.GetType() <> GetType(Varigence.Languages.Biml.Table.AstTableColumnTableReferenceNode)) #> <Property PropertyName="MetaData.<#= tbl.name#>.<#= col.Name #>"><Value><#= datrow(col.name)#></Value></Property> <# next #> </Properties> <Relationships> <# for each fk in tbl.Columns.OfType(Of AstTableColumnTableReferenceNode) #> <Relationship RelationshipName="MetaData.<#= tbl.Name #>.<#= fk.ForeignTable #>" RelatedItemName="<#= fk.ForeignTable #>.<#= datrow(fk.name)#>"></Relationship> <# next #> </Relationships> </DataItem> <# next#> </DataItems> </Entity> <# next #> </Entities> </MetadataInstance> </Metadata> </Biml>
Should you be using BimlExpress, this Feature is not available to you. This post explains another approach on how to derive metadata from SQL Server to Biml.
Any questions or comments? We’d love to hear from you at !
Further Information on Biml in English can be found on our English Biml Page.
Happy Biml’ing!
Sofern Sie BimlExpress nutzen, so steht Ihnen dieses Feature nicht zur Verfügung. Dieser Beitrag zeigt einen weiteren Weg auf, um Metadaten aus dem SQL Server in Biml nutzbar zu machen.
Haben Sie hierzu Fragen oder Anmerkungen? Wir freuen uns auf Ihren Input unter !
Weitere Informationen zu Biml, einschließlich Terminen und Blog Beiträgen finden Sie auch auf unserer Biml Seite.
Viel Spaß beim Biml’n!