Created
August 10, 2012 08:46
-
-
Save mikeminutillo/3312671 to your computer and use it in GitHub Desktop.
LINQPad DataDictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ignoredColumns = new[] { | |
"CreatedBy", | |
"CreatedDate", | |
"ModifiedBy", | |
"ModifiedDate", | |
"LogicallyDeletedBy", | |
"LogicallyDeletedDate", | |
"LastModified" | |
}; | |
var ignoredTables = from t in this.Mapping.GetTables() | |
where t.TableName.StartsWith("[_") | |
|| t.TableName.StartsWith("[History]") | |
|| t.TableName.StartsWith("[sys") | |
|| t.TableName.StartsWith("[tmp") | |
|| t.TableName.StartsWith("[Admin]") | |
|| t.TableName.StartsWith("[Ssis") | |
select t; | |
var things = (from t in this.Mapping.GetTables().Except(ignoredTables) | |
select new { | |
TableName = t.TableName.Trim('[', ']'), | |
Columns = t.RowType.DataMembers.Where(x => x.IsAssociation == false).Select(x => x.Name).Except(ignoredColumns).ToArray(), | |
Relationships = (from a in t.RowType.Associations | |
select new | |
{ | |
ThisKey = String.Join(", ", a.ThisKey.Select(x => x.Name)), | |
OtherEntity = a.OtherType.Name, | |
OtherKey = String.Join(", ", a.OtherKey.Select(x => x.Name)), | |
IsOutgoing = a.IsForeignKey | |
}).ToArray() | |
}); | |
foreach(var thing in things) | |
{ | |
LINQPad.Util.RawHtml(String.Format("<a href=\"#{0}\" >{0}</a>", thing.TableName)).Dump(); | |
} | |
foreach(var thing in things) | |
{ | |
LINQPad.Util.RawHtml(String.Format("<a name=\"{0}\" /><h1>{0}</h1>", thing.TableName)).Dump(); | |
foreach(var column in thing.Columns) Console.WriteLine(column); | |
var outgoing = thing.Relationships.Where(x => x.IsOutgoing); | |
if(outgoing.Any()) LINQPad.Util.RawHtml("<h2>Outgoing Relationships</h2>").Dump(); | |
foreach(var ogr in outgoing) LINQPad.Util.RawHtml(String.Format("{0} -> <a href=\"#{1}\">{1}</a>.{2}", ogr.ThisKey, ogr.OtherEntity, ogr.OtherKey)).Dump(); | |
var incoming = thing.Relationships.Where(x => x.IsOutgoing == false); | |
if(incoming.Any()) LINQPad.Util.RawHtml("<h2>Incoming Relationships</h2>").Dump(); | |
foreach(var icr in incoming) LINQPad.Util.RawHtml(String.Format("{0} <- <a href=\"#{1}\">{1}</a>.{2}", icr.ThisKey, icr.OtherEntity, icr.OtherKey)).Dump(); | |
Console.WriteLine(); | |
LINQPad.Util.RawHtml("<hr />").Dump(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment