Living in the Tech Avalanche Generation

A practitioner’s introspective on technology
Archive for March 23rd, 2009

Entity Framework Profiler - Progress

In my last post I spoke about a Profiler for the Entity Framework that I have been working on as a proof of concept and ultimately as a tool for personal use and by extension, anyone else who can find a use for it.

Previously I posted a single image as a preview of the User Interface. At that point in time the UI was particularly empty and didn’t really outline or describe the data that the Profiler would provide the user. In an effort to build some anticipation, I thought it might be useful to give one last look at the application before I post the code in the next few days at which point I expect it will be useful and easily setup to run for an end user.

Meta View (without expanded data)

ef_prof_tests_with_meta_not_collapsed

This image above shows some data relating to an Entity Model that has executed queries. The ‘Meta’ tab offers some context regarding the underlying ObjectContext EntitySet and it’s type, it also contains the SQL executed and the field meta data, as is apparent when the expanders are collapsed as per the next image below. The meta data is derived directly out of the MetaDataWorkspace in the Entity Framework itself. Here is a snippet of the code:

var query =
    from meta in ctx.MetadataWorkspace.
        GetEntityContainer(ctx.DefaultContainerName,
        DataSpace.CSpace).BaseEntitySets
    let fields = from f in meta.ElementType.Members.ToList()
                 select new
                 {
                     FieldName = f.Name,
                     FieldType = f.TypeUsage.EdmType.Name
                 }
    where meta.BuiltInTypeKind == BuiltInTypeKind.EntitySet &&
          meta.Name == eventArgs.Method.Name.Replace(“get_”, “”)
    select new
    {
        EntitySetName = meta.Name,
        EntityName = meta.ElementType.Name,
        Members = fields
    };

Meta View (expanded)

ef_prof_tests_with_meta_collapsed

The next image displays a view that contains a dedicated view of the SQL that has been executed. The SQL Text window is provided by a free (slightly re-worked) third party user control (more on that later).

SQL View

ef_prof_tests_with_sql_view

Here is the code run against the Entity Model that was profiled, producing the data displayed in the images exhibited in this post.

public class EFProfilerIntegrationTests
{
    public void message_sent_with_sqltext1()
    {
        NorthwindEntities ctx =
            new NorthwindEntities();
        var custs = from c in ctx.Customers
                    select c;
    }

    public void message_sent_with_sqltext2()
    {
        NorthwindEntities ctx =
            new NorthwindEntities();
        var custs = from c in ctx.Orders
                    select c;
    }

    public void message_sent_with_sqltext3()
    {
        NorthwindEntities ctx =
            new NorthwindEntities();
        var custs = from c in ctx.OrderLines
                    select c;
    }
}

ef_prof_entity_model

The menu currently has no functionality but I plan to use it for saving and reading back data to and from disk allowing users to execute a playback of previous sessions profiled. I expect to get a working copy of the code posted sometime over the next few days or so. Remember I am keen to hear functionality requests.

Share/Save/Bookmark

No comments

Creative Commons Attribution-ShareAlike 2.5 Australia
Creative Commons Attribution-ShareAlike 2.5 Australia