Tiraggo.edmx

Full EDMX Metadata Served up with low level SQL Metadata


Project maintained by BrewDawg Hosted on GitHub Pages — Theme by mattgraham

An Awesome way to Access your EDMX file Metadata

Copyright © Mike Griffin 2013
Mikes Personal Site
Mikes Twitter Account

License: MIT

NuGet Package install from within Visual Studio using the NuGet Package Manager.

Please, if you like TiraggoEdmx spread the word via Twitter or your Blog ...


TiraggoEdmx is a metadata engine that is capable of serving up all of the data in your EDMX file(s). This includes the mappings between your conceptual columns and physical database columns. You can get the low level SQL information and data types. EDMX versions 2 and 3 are both supported. Typically version 2 is created using VS2010 and version 3 is created using VS2012.

There is a Windows.Forms sample you can run in the TiraggoEdmx github repository, it's a great way to set a break point and examine the metadata by expanding the "edmx" class in the debugger.

Let's take a look at how you use the 'TiraggoEntityInfo' class.

// Typical T4 Toolbox Classes Here
MetadataLoader loader = new MetadataLoader(this);
EdmItemCollection items = loader.CreateEdmItemCollection(inputFile);

// TiraggoEdmx code now ...
Edmx edmx = Edmx.Load(@"Model1.edmx");

// We use the loader to get the entity names in our .edmx
foreach (EntityType e in items.GetItems<EntityType>().OrderBy(a => a.Name))
{
    // Everthing you need including your low level SQL metadata types
    TiraggoEntityInfo info = new TiraggoEntityInfo(edmx, e.FullName);

    string schema = info.StorageInfo.Schema;  // dbo
    string table = info.StorageInfo.Name;     // Employees

    foreach (tgProperty prop in info.ConceptualModel.Properties)
    {
        // prop.Name is conceptual name, let's get the physical name
        string physicalColumName = info.ColumnMappings[prop.Name];

        // Let's now get the low level SQL info using the physical name
        tgProperty sqlInfo = info.ColumnSQL[physicalColumName];

        // Now we have the low level SQL Information
        string s1 = sqlInfo.Type; // nvarchar, datetime, ...
        string s2 = sqlInfo.Name; // physical column name
        // and so on with many more properties on sqlInfo ...
    }
}

After installing TiraggoEdmx you will have two sample T4 templates installed in your "Models" folder. One is for V2 edmx files and the other is for V3 edmx files. They will both run fine, however, only one will generate code (depending on which version of edmx files you're using).

The TiraggoEdmx sample templates generate simple classes and are only meant to show you how to use the metadata and more specifically how to the underlying low level information very easily. The classes generated will look something like this. Keep in the mind the comments in the class below were also generated via the template.

namespace MyNamespace.Models.TiraggoEdmx
{
    // Physical Table [dbo.CollaboratorInvite]
    public partial class CollaboratorInvite
    {
        // Physical SQL Column [Id], Type [uniqueidentifier]
        [Key]
        [Required]
        public Guid MemberId { get; set; }

        // Physical SQL Column [CollborationKey], Type [nvarchar]
        [Key]
        [Required]
        public String CollborationKey { get; set; }

        // Physical SQL Column [RepositoryId], Type [uniqueidentifier]
        [Required]
        public Guid RepositoryId { get; set; }

        // Physical SQL Column [InviteeId], Type [uniqueidentifier]
        [Required]
        public Guid InviteeId { get; set; }

        // Physical SQL Column [DateCreatedOn], Type [datetime]
        public DateTime CreatedOn { get; set; }
    }
}

Tiraggo.EF which creates the Tiraggo Dynamic Query classes uses the TiraggoEdmx metadata library for it's T4 code generation needs.