Living in the Tech Avalanche Generation

A practitioner’s introspective on technology

Entity Framework Profiler hosts IronRuby and IronPython

I mentioned recently that I wanted to add IronRuby scripting into the profiler so users could compose scripts and execute Entity Framework code directly from the Profiler itself. After looking around at how to host IronRuby in my own application it became clear very quickly that I was about to set out on building something quite redundantly. IronEditor, DLRPAD to name a few, offer this functionality, so all I needed was to grab one such tool whose license and functionality were a match. I decided on IronEditor. IronEditor is a Windows Forms application that embeds a IronRuby console and allows both IronRuby and IronPython scripting, so immediately I gained a benefit of adding support to both languages.

Unfortunately IronEditor has a lot of the required code embedded in a Windows Form causing me to rework the source a little to turn the Form in to a User Control which I can easily host in the profiler using the WPF Windows Forms Host. This will also require some reworking of the WCF code, as the client and server will be in the same application and to be frank WCF is overkill and I am going to refactor the messaging with sockets more than likely. It’s not quite ready but here’s a screen shot of what to expect.

Exhibit 1.0

PROF

Exhibit 1.0 demonstrates the an IronRuby script that works against one of my C# Entity Framework Repository libraries.

Exhibit 2.0

PROF_QUERY_IRON

Exhibit 2.0 displays the TSQL that is run as result of the one of the queries that are run by the IronRuby script.

Exhibit 3.0

PROF_QUERY_IRON_META

Exhibit 3.0 shows the Meta Data View also produced by running the same IronRuby script.

The IronRuby Script

require ‘System.Windows.Forms, Version=2.0.0.0, ‘ +
    ‘Culture=neutral, PublicKeyToken=b77a5c561934e089′
require ‘D:/simon.segal/Local Working/Org.TechA.EF.Profiler’ +
    ‘/Org.TechA.EF.Profiler.Tests/bin/Debug’ +
    ‘/Org.TechA.EF.Profiler.Tests.dll’
require ‘System.Data, Version=2.0.0.0, ‘ +
    ‘Culture=neutral, PublicKeyToken=b77a5c561934e089′
require ‘System.Data.DataSetExtensions, ‘ +
    ‘Version=3.5.0.0, Culture=neutral, ‘ +
    ‘PublicKeyToken=b77a5c561934e089′
require ‘System.Data.Entity, Version=3.5.0.0, ‘ +
    ‘Culture=neutral, PublicKeyToken=b77a5c561934e089′
require ‘System.Core, Version=3.5.0.0, ‘ +
    ‘Culture=neutral, PublicKeyToken=b77a5c561934e089′

$providerName = “System.Data.SqlClient”
$serverName = “boomer”
$databaseName = “Northwind”

#Initialize the connection string builder For the
#underlying provider.
$sqlBuilder = System::Data::SqlClient::
                SqlConnectionStringBuilder.new

#Set the properties For the data source.
$sqlBuilder.DataSource = $serverName
$sqlBuilder.InitialCatalog = $databaseName
$sqlBuilder.IntegratedSecurity = true

#Build the SqlConnection connection string.
$providerString =
    $sqlBuilder.ToString()

#Initialize the EntityConnectionStringBuilder.
$entityBuilder = System::Data::EntityClient::
    EntityConnectionStringBuilder.new

#Set the provider name.
$entityBuilder.Provider = $providerName

#Set the provider-specIfic connection string.
$entityBuilder.ProviderConnectionString = $providerString

#Set the Metadata location.
$entityBuilder.Metadata =
    “res://*/NorthWindModel.csdl|res://*/” +
    “NorthWindModel.ssdl|res://*/NorthWindModel.msl”

#get the connection string
$con = $entityBuilder.ToString()

puts $con

#set up the ObjectContext
$session = Org::TechA::EF::Profiler::Tests::NorthwindEntities.new($con)

#Get all the customers
$custs = $session.Customers

$custs.each {|cust| puts cust.CompanyName}

#Get all the orders
$orders = $session.Orders

$orders.each {|order| puts order.OrderID}

So more than just pictures?

I expect to have a working revision out within a week or so but the current version without the scripting ability is still available here.

Share/Save/Bookmark

1 Comment so far

  1. [...] had already posted about what to expect from the next iteration of the Profiler and I won’t repeat it here, so if your new to the tool I [...]

Leave a reply

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