﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com/blog/</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2012 (c) 2012</copyright><ttl>60</ttl><item><title>Application analysis: Northwind.NET</title><description>&lt;p&gt;For an article I am writing, I wanted to compare a RavenDB model to a relational model, and I stumbled upon the following &lt;a href="http://northwind.codeplex.com/"&gt;Northwind.NET project&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;I plugged in the &lt;a href="http://efprof.com"&gt;Entity Framework Profiler&lt;/a&gt; and set out to watch what was going on. To be truthful, I expected it to be bad, but I honestly did &lt;em&gt;not&lt;/em&gt; expect what I got. Here is a question, how many queries does it take to render the following screen?&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Application-analysis_B141/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Application-analysis_B141/image_thumb.png" width="940" height="693"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The answer, believe it or no, is 17:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Application-analysis_B141/image_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Application-analysis_B141/image_thumb_1.png" width="771" height="409"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You might have noticed that most of the queries look quite similar, and indeed, they &lt;em&gt;are&lt;/em&gt;. We are talking about 16(!) identical queries:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; [Extent1].[ID]           &lt;span class="kwrd"&gt;AS&lt;/span&gt; [ID],
       [Extent1].[Name]         &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Name],
       [Extent1].[Description]  &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Description],
       [Extent1].[Picture]      &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Picture],
       [Extent1].[RowTimeStamp] &lt;span class="kwrd"&gt;AS&lt;/span&gt; [RowTimeStamp]
&lt;span class="kwrd"&gt;FROM&lt;/span&gt;   [dbo].[Category] &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Extent1]&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;Looking at the stack trace for one of those queries led me to:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Application-analysis_B141/image_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Application-analysis_B141/image_thumb_2.png" width="1014" height="352"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And to this piece of code:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Application-analysis_B141/image_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Application-analysis_B141/image_thumb_3.png" width="758" height="371"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;You might note that dynamic is used there, for what reason, I cannot even guess. Just to check, I added a ToArray() to the result of GetEntitySet, and the number of queries dropped from 17 to 2, which is more reasonable. The problem was that we passed an IQueryable to the data binding engine, which ended up evaluating the query multiple times.&lt;/p&gt;
&lt;p&gt;And &lt;a href="http://efprof.com"&gt;EF Prof&lt;/a&gt; actually warns about that, too:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Application-analysis_B141/image_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Application-analysis_B141/image_thumb_4.png" width="763" height="120"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;At any rate, I am afraid that this project suffer from similar issues all around, it is actually too bad to serve as the bad example that I intended it to be.&lt;/p&gt;</description><link>http://ayende.com/blog/152705/application-analysis-northwind-net?key=50a77d7b-0d0f-4b53-9305-eba261b563c1</link><guid>http://ayende.com/blog/152705/application-analysis-northwind-net?key=50a77d7b-0d0f-4b53-9305-eba261b563c1</guid><pubDate>Fri, 30 Dec 2011 10:00:00 GMT</pubDate></item><item><title>Gilad Shalit is back</title><description>&lt;p&gt;I don’t usually do posts about current events, but &lt;a href="http://www.ynetnews.com/articles/0,7340,L-4136451,00.html"&gt;this one is huge&lt;/a&gt;. &lt;/p&gt; &lt;p&gt;To celebrate the event, you can use the following coupon code: SLT-45K2D4692G to get 19.41% discount (Gilad was captive for 1,941 days) for all our profilers:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://nhprof.com/"&gt;NHibernate Profiler&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://efprof.com/"&gt;Entity Framework Profiler&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://l2sprof.com/"&gt;Linq to SQL Profiler&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://llblgenprof.com/"&gt;LLBLGen Profiler&lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="http://hibernateprofiler.com/"&gt;Hibernate Profiler&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Hell, even our &lt;a href="http://nhprof.com/commercialsupport"&gt;commercial support for NHibernate&lt;/a&gt; is participating.&lt;/p&gt; &lt;p&gt;Please note that any political comment to this post that I don’t agree with will be deleted.&lt;/p&gt;</description><link>http://ayende.com/blog/130049/gilad-shalit-is-back?key=b8b09d35-b65b-4925-9046-a6315d3899aa</link><guid>http://ayende.com/blog/130049/gilad-shalit-is-back?key=b8b09d35-b65b-4925-9046-a6315d3899aa</guid><pubDate>Tue, 18 Oct 2011 10:00:00 GMT</pubDate></item><item><title>Entity Framework 4.1 Update 1, Backward Compatibility and Microsoft</title><description>&lt;p&gt;One of the things that you keep hearing about Microsoft products is how much time and effort is dedicated to ensuring Backward Compatibility. I have had a lot of arguments with Microsoft people about certain design decisions that they have made, and usually the argument ended up with “We have to do it this was to ensure Backward Compatibility”. &lt;/p&gt; &lt;p&gt;That sucked, but at least I could sleep soundly, knowing that if I had software running on version X of Microsoft, I could at least be pretty sure that it would work in X+1.&lt;/p&gt; &lt;p&gt;Until Entity Framework 4.1 Update 1 shipped, that is. &lt;a href="http://weblogs.asp.net/fbouma/archive/2011/07/28/entity-framework-v4-1-update-1-the-kill-the-tool-eco-system-version.aspx"&gt;Frans Bouma has done a great job in describing what the problem actually is&lt;/a&gt;, including going all the way and actually submitting a patch with the code required to fix this issue.&lt;/p&gt; &lt;p&gt;But basically, starting with Entity Framework 4.1 Update 1 (the issue also appears in Entity Framework 4.2 CTP, but I don’t care about this much now), you can’t use generic providers with Entity Framework. Just to explain, generic providers is pretty much the one way that you can integrate with Entity Framework if you want to write a profiler or a cacher or a… you get the point.&lt;/p&gt; &lt;p&gt;Looking at the code, it is pretty obvious that this is &lt;em&gt;not&lt;/em&gt; intentional, but just someone deciding to implement a method without considering the full ramifications. When I found out about the bug, I tried figuring out a way to resolve it, but the only work around would require me to provide a different assembly for each provider that I wanted to support (and there are dozens that we support on EF 4.0 and EF 3.5 right now).&lt;/p&gt; &lt;p&gt;We have currently &lt;strong&gt;implemented a work around for SQL Server only&lt;/strong&gt;, but if you want to use Entity Framework Profiler with Entity Framework 4.1 Update 1 and a database other than SQL Server, we would have to create a special build for your scenario, rather than have you use the generic provider method, which have worked so far. &lt;/p&gt; &lt;p&gt;Remember the beginning of this post? How I said that Backward Compatibility is something that Microsoft is taking so seriously? &lt;/p&gt; &lt;p&gt;Naturally I felt that this (a bug that impacts anyone who extends Entity Framework in such a drastic way) is an important issue to raise with Microsoft. So I contacted the team with my finding, and the response that I got was basically: Use the old version if you want this supported.&lt;/p&gt; &lt;p&gt;What I &lt;em&gt;didn’t &lt;/em&gt;get was:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Addressing the issue of a breaking change of this magnitude that isn’t even on a major release, it is an &lt;em&gt;update to a minor release.&lt;/em&gt;&lt;/li&gt; &lt;li&gt;Whatever they are even going to fix it, and when this is going to be out.&lt;/li&gt; &lt;li&gt;Whatever the next version (4.2 CTP also have this bug) is going to carry on this issue or not.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;I find this unacceptable. The fact that there is a problem with a CTP is annoying, but not that important. The fact that a &lt;em&gt;fully release package&lt;/em&gt; has this backward compatibility issue is horrible.  &lt;p&gt;What makes it even worse is the fact that this is an update to a minor version, people excepts this to be a safe upgrade, not something that requires full testing. And &lt;em&gt;anyone&lt;/em&gt; who is going to be running Update-Package in VS is going to hit this problem, and Update-Package is something that people do very often. And suddenly, Entity Framework Profiler can no longer work.  &lt;p&gt;Considering the costs that the entire .NET community has to bear in order for Microsoft to preserve backward compatibility, I am deeply disappointed that when I actually need this backward compatibility.  &lt;p&gt;This is from the same guys that refused (for five years!) to fix &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/details/93559/typeconverter-for-value-types-such-as-int-bool-short-etc-return-true-to-isvalid-even-if-the-value-is-not-valid"&gt;this bug&lt;/a&gt;: &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;new&lt;/span&gt; System.ComponentModel.Int32Converter().IsValid(&lt;span class="str"&gt;"yellow"&lt;/span&gt;) == true&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;/blockquote&gt;
&lt;p&gt;Because, and I quote:
&lt;blockquote&gt;
&lt;p&gt;We do not have the luxury of making that risky assumption that people will not be affected by the potential change. I know this can be frustrating for you as it is for us. Thanks for your understanding in this matter.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Let me put this to you in perspective, anyone who is using EF Prof is likely to (almost by chance) to get hit by that. When this happens, our only option is to tell them to switch back a version? 
&lt;p&gt;That makes &lt;em&gt;us &lt;/em&gt;look very bad, &lt;em&gt;regardless&lt;/em&gt; of what is the actual reason for that. That means that I am having to undermine my users' trust in my product. "He isn't supporting 4.1, and he might not support 4.2, so we probably can't buy his product, because we want to have the newest version". 
&lt;p&gt;This is very upsetting. Not so much about the actual bug, those happen, and I can easily imagine the guy writing the code making assumptions that turn out to be false. Heavens know that I have done the same many times before. I don’t even worry too much about this having escaped the famous Microsoft Testing Cycle. 
&lt;p&gt;What (to be frank) pisses me off is that the response that we got from Microsoft for this was that they aren’t going to fix this. That the only choice that I have it to tell people to downgrade if they want to use my product (with all the implications that has for my product).&lt;/p&gt;
&lt;p&gt;&lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-sadsmile" alt="Sad smile" src="http://ayende.com/blog/Images/Windows-Live-Writer/Entity-Framework-4.1_B4A0/wlEmoticon-sadsmile_2.png"&gt;&lt;/p&gt;</description><link>http://ayende.com/blog/75777/entity-framework-4-1-update-1-backward-compatibility-and-microsoft?key=72c586ff-448c-420b-bdc4-214f3a172040</link><guid>http://ayende.com/blog/75777/entity-framework-4-1-update-1-backward-compatibility-and-microsoft?key=72c586ff-448c-420b-bdc4-214f3a172040</guid><pubDate>Fri, 05 Aug 2011 09:00:00 GMT</pubDate></item><item><title>What is next for the profilers?</title><description>&lt;p&gt;We have been working on the profilers (&lt;a href="http://nhprof.com/"&gt;NHibernate Profiler&lt;/a&gt;, &lt;a href="http://efprof.com/"&gt;Entity Framework Profiler&lt;/a&gt;, &lt;a href="http://l2sprof.com/"&gt;Linq to SQL Profiler&lt;/a&gt;, &lt;a href="http://llblgenprof.com/"&gt;LLBLGen Profiler&lt;/a&gt; and &lt;a href="http://hibernateprofiler.com"&gt;Hibernate Profiler&lt;/a&gt;) for close to three years now. And we have been running always as 1.x, so we didn’t have a major release (although we have continual releases, we currently have close to 900 drops of the 1.x version).&lt;/p&gt; &lt;p&gt;The question now becomes, what is going to happen in the next version of the profiler?&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Production Profiling, the ability to setup your application so that you can connect to your production application and see what is going on &lt;em&gt;right now&lt;/em&gt;. &lt;/li&gt; &lt;li&gt;Error Analysis, the ability to provide you with additional insight and common solution to recurring problems.&lt;/li&gt; &lt;li&gt;Global Query Analysis, the ability to take all of your queries, look at their query plans and show your potential issues.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Those are the big ones, we have a few others, and a surprise in store &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://ayende.com/blog/Images/Windows-Live-Writer/What-is-next-for-the-profilers_868C/wlEmoticon-smile_2.png"&gt;&lt;/p&gt; &lt;p&gt;What would you want to see in the next version of the profiler?&lt;/p&gt;</description><link>http://ayende.com/blog/11265/what-is-next-for-the-profilers?key=98ae56ef-3200-41b0-beec-1c206cbe1608</link><guid>http://ayende.com/blog/11265/what-is-next-for-the-profilers?key=98ae56ef-3200-41b0-beec-1c206cbe1608</guid><pubDate>Thu, 02 Jun 2011 09:00:00 GMT</pubDate></item><item><title>Uber Prof &amp;amp; NuGet</title><description>&lt;p&gt;Fitzchak has all the details in our &lt;a href="http://blogs.hibernatingrhinos.com/archive/2011/03/31/nuget-packages-and-an-example-use-of-the-profiler.aspx"&gt;company blog&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;img alt="NugetPackages" src="http://blogs.hibernatingrhinos.com/images/blogs_hibernatingrhinos_com/Windows-Live-Writer/33b8e30a3166_9ED0/NugetPackages_thumb_1.png" /&gt;&lt;/p&gt;</description><link>http://ayende.com/blog/4799/uber-prof-amp-nuget?key=e4deb5ce-de52-4c43-89ba-2c3f410d2801</link><guid>http://ayende.com/blog/4799/uber-prof-amp-nuget?key=e4deb5ce-de52-4c43-89ba-2c3f410d2801</guid><pubDate>Fri, 01 Apr 2011 11:00:00 GMT</pubDate></item><item><title>New Profiler Feature: Avoid Writes from Multiple Sessions In The Same Request</title><description>&lt;p&gt;Because I keep getting asked, this feature is available for the following profilers:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://nhprof.com/"&gt;NHibernate Profiler&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://efprof.com/"&gt;Entity Framework Profiler&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://l2sprof.com/"&gt;Linq to SQL Profiler&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://llblgenprof.com/"&gt;LLBLGen Profiler&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://hibernateprofiler.com/"&gt;Hibernate Profiler&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This new feature detects a very interesting bad practice, write to the database from multiple session in the same web request.&lt;/p&gt;  &lt;p&gt;For example, consider the following code:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SaveAccount(Account account)
{
    &lt;span class="kwrd"&gt;using&lt;/span&gt;(var session = sessionFactory.OpenSession())
    &lt;span class="kwrd"&gt;using&lt;/span&gt;(session.BeginTransaction())
    {
           session.SaveOrUpdate(account);
           session.Transaction.Commit();    
    }
}&lt;/pre&gt;

  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; Account GetAccount(&lt;span class="kwrd"&gt;int&lt;/span&gt; id)
{
    &lt;span class="kwrd"&gt;using&lt;/span&gt;(var session = sessionFactory.OpenSession())
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; session.Get&amp;lt;Account&amp;gt;(id);
    }
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;It is bad for several reasons, micro managing the session is just one of them, but the worst part is yet to come…&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; MakePayment(&lt;span class="kwrd"&gt;int&lt;/span&gt; fromAccount, &lt;span class="kwrd"&gt;int&lt;/span&gt; toAccount, &lt;span class="kwrd"&gt;decimal&lt;/span&gt; ammount)
{
    var from = Dao.GetAccount(fromAccount);
    var to = Dao.GetAccount(toAccount);
    from.Total -= amount;
    to.Total += amount;
    Dao.SaveAccount(from);
    Dao.SaveAccount(to);
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;Do you see the error here? There are actually several, let me count them:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;We are using 4 different connections to the database in a single method.&lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;We don’t have transactional safety!!!!&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think about it, if the server crashed between the fifth and sixth lines of this method, where would we be? &lt;/p&gt;

&lt;p&gt;We would be in that wonderful land where money disappear into thin air and we stare at that lovely lawsuit folder and then jump from a high window to a stormy sea.&lt;/p&gt;

&lt;p&gt;Or, of course, you could use the profiler, which will tell you that you are doing something which should be avoided:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/Windows-Live-Writer/New-Alert-Multiple-Write-Sessions-In-The_C8D8/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/Windows-Live-Writer/New-Alert-Multiple-Write-Sessions-In-The_C8D8/image_thumb.png" width="775" height="110" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Isn’t that better than swimming with the sharks?&lt;/p&gt;</description><link>http://ayende.com/blog/4775/new-profiler-feature-avoid-writes-from-multiple-sessions-in-the-same-request?key=7f102633-ec3a-497f-b84f-8c191dab2292</link><guid>http://ayende.com/blog/4775/new-profiler-feature-avoid-writes-from-multiple-sessions-in-the-same-request?key=7f102633-ec3a-497f-b84f-8c191dab2292</guid><pubDate>Tue, 01 Mar 2011 12:26:00 GMT</pubDate></item><item><title>New Uber Prof Feature: Too Many Database Calls In The Same Request</title><description>&lt;p&gt;&lt;font size="3"&gt;Recently, we added a way to track alerts across all the sessions the request. This alert will detect whenever you are making too many database calls in the same request.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;But wait, don’t we already have that?&lt;/p&gt;  &lt;p&gt;Yes, we do, but that was limited to the scope of one session. there is a very large set of codebases where the usage of OR/Ms is… suboptimal (in other words, they could take the most advantage of the profiler abilities to detect issues and suggest solutions to them), but because of the way they are structured, they weren’t previously detected.&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;What is the difference between a session and a request? &lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="3"&gt;Note: I am using NHibernate terms here, but naturally this feature is shared among all profiler:&lt;/font&gt;&lt;/p&gt;    &lt;ul&gt;     &lt;li&gt;&lt;a href="http://nhprof.com/"&gt;NHibernate Profiler&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://efprof.com/"&gt;Entity Framework Profiler&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://l2sprof.com/"&gt;Linq to SQL Profiler&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://llblgenprof.com/"&gt;LLBLGen Profiler&lt;/a&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://hibernateprofiler.com/"&gt;Hibernate Profiler&lt;/a&gt;&lt;/li&gt;   &lt;/ul&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;font size="3"&gt;A session is the NHibernate session (or the data/object context in linq to sql / entity framework), and the request is the HTTP request or the WCF operation. If you had code such as the following:&lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; T GetEntity&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;int&lt;/span&gt; id)
{
    &lt;span class="kwrd"&gt;using&lt;/span&gt; (var session = sessionFactory.OpenSession())
    {
         &lt;span class="kwrd"&gt;return&lt;/span&gt; session.Get&amp;lt;T&amp;gt;(id);
    }
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;This code is bad, it micro manages the session, it uses too many connections to the database, it … well, you get the point. The problem is that code that uses this code:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerable&amp;lt;Friends&amp;gt; GetFriends(&lt;span class="kwrd"&gt;int&lt;/span&gt;[] friends)
{
   var results = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Friends&amp;gt;();
   &lt;span class="kwrd"&gt;foreach&lt;/span&gt;(var id &lt;span class="kwrd"&gt;in&lt;/span&gt; friends)
       results.Add(GetEnttiy&amp;lt;Friend&amp;gt;(id));

   &lt;span class="kwrd"&gt;return&lt;/span&gt; results;
}&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;The code above would look like the following in the profiler:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/Windows-Live-Writer/New-Alert-Too-Many-Database-Calls-In-The_C8E2/Image1.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Image1" border="0" alt="Image1" src="http://ayende.com/Blog/images/ayende_com/Blog/Windows-Live-Writer/New-Alert-Too-Many-Database-Calls-In-The_C8E2/Image1_thumb.png" width="251" height="400" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, each call is in a separate session, and previously, we wouldn’t have been able to detect that you have too many calls (because each call is a separate session).&lt;/p&gt;

&lt;p&gt;Now, however, we will alert the user with a too many database calls in the same request alerts. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/Windows-Live-Writer/New-Alert-Too-Many-Database-Calls-In-The_C8E2/Image2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Image2" border="0" alt="Image2" src="http://ayende.com/Blog/images/ayende_com/Blog/Windows-Live-Writer/New-Alert-Too-Many-Database-Calls-In-The_C8E2/Image2_thumb.png" width="699" height="317" /&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://ayende.com/blog/4774/new-uber-prof-feature-too-many-database-calls-in-the-same-request?key=5fe23059-c0d9-4990-8c16-0372c0ee5bac</link><guid>http://ayende.com/blog/4774/new-uber-prof-feature-too-many-database-calls-in-the-same-request?key=5fe23059-c0d9-4990-8c16-0372c0ee5bac</guid><pubDate>Mon, 28 Feb 2011 12:15:00 GMT</pubDate></item><item><title>New Uber Prof Concept: Cross Session Alerts</title><description>&lt;p&gt;We have recently been doing some work on Uber Prof, mostly in the sense of a code review, and I wanted to demonstrate how easy it was to add a new feature. The problem is that we couldn’t really think of a nice feature to add that we didn’t already have. &lt;/p&gt;  &lt;p&gt;Then we started thinking about features that aren’t there and that there wasn’t anything in Uber Prof to enable, and we reached the conclusion that one limitation we have right now is the inability to analyze your application’s behavior beyond the session’s level. But there is actually a whole &lt;em&gt;set&lt;/em&gt; of bad practices that are there when you are using multiple sessions.&lt;/p&gt;  &lt;p&gt;That led to the creation of a new concept the Cross Session Alert, unlike the alerts we had so far, those alerts looks at the data stream with a much broader scope, and they can analyze and detect issues that we previously couldn’t detect.&lt;/p&gt;  &lt;p&gt;I am going to be posting extensively on some of the new features in just a bit, but in the meantime, why don’t you tell me what sort of features do you think this new concept is enabling.&lt;/p&gt;  &lt;p&gt;And just a reminder, my architecture is based around &lt;a href="http://ayende.com/Blog/archive/2009/03/06/application-structure-concepts-amp-features.aspx"&gt;Concepts &amp;amp; Features&lt;/a&gt;.&lt;/p&gt;</description><link>http://ayende.com/blog/4773/new-uber-prof-concept-cross-session-alerts?key=eeebdd89-c238-4266-b655-fc2be2a2ae50</link><guid>http://ayende.com/blog/4773/new-uber-prof-concept-cross-session-alerts?key=eeebdd89-c238-4266-b655-fc2be2a2ae50</guid><pubDate>Fri, 25 Feb 2011 10:05:00 GMT</pubDate></item><item><title>Uber Prof New Features: A better query plan</title><description>&lt;blockquote&gt;Originally posted at 1/7/2011&lt;/blockquote&gt;&lt;p&gt;Because I keep getting asked, this feature is available for the following profilers:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://nhprof.com"&gt;NHibernate Profiler&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://efprof.com"&gt;Entity Framework Profiler&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://l2sprof.com"&gt;Linq to SQL Profiler&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://llblgenprof.com"&gt;LLBLGen Profiler&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://hibernateprofiler.com"&gt;Hibernate Profiler&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This feature is actually two separate ones. The first is the profiler detecting what is the most expensive part of the query plan and making it instantly visible. As you can see, in this fairly complex query, it is this select statement that is the hot spot.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/UberProfNewFeaturesAbetterqueryplan_CDD8/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/UberProfNewFeaturesAbetterqueryplan_CDD8/image_thumb_3.png" width="1132" height="666" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p /&gt;  &lt;p /&gt;  &lt;p /&gt;  &lt;p&gt;Another interesting feature that only crops up whenever we are dealing with complex query plans is that the query plan can get &lt;em&gt;big&lt;/em&gt;. And by that I mean &lt;em&gt;really&lt;/em&gt; big. Too big for a single screen.&lt;/p&gt;  &lt;p&gt;Therefore, we added zooming capabilities as well as the mini map that you see in the top right corner.&lt;/p&gt;</description><link>http://ayende.com/blog/4752/uber-prof-new-features-a-better-query-plan?key=7d9a03d2-2816-444d-a87c-5750ccf802f3</link><guid>http://ayende.com/blog/4752/uber-prof-new-features-a-better-query-plan?key=7d9a03d2-2816-444d-a87c-5750ccf802f3</guid><pubDate>Sat, 15 Jan 2011 10:00:00 GMT</pubDate></item><item><title>Uber Prof New Features: Go To Session from alert</title><description>&lt;blockquote&gt;Originally posted at 1/7/2011&lt;/blockquote&gt;&lt;p&gt;This is another oft requested feature that we just implemented. The new feature is available for the full suite of Uber Profilers:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://nhprof.com"&gt;NHibernate Profiler&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://efprof.com"&gt;Entity Framework Profiler&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://l2sprof.com"&gt;Linq to SQL Profiler&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://llblgenprof.com"&gt;LLBLGen Profiler&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://hibernateprofiler.com"&gt;Hibernate Profiler&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;You can see the new feature below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/UberProfNewFeaturesGoToSessionfromalert_C9AD/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/UberProfNewFeaturesGoToSessionfromalert_C9AD/image_thumb.png" width="1094" height="388" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I think it is cute, and was surprisingly easy to do.&lt;/p&gt;  &lt;p&gt;Uber Prof have recently passed the stage where it is mostly implemented using itself, so I just had to wire a few things together, and then I spent most of the time just making sure that things aligned correctly on the UI.&lt;/p&gt;</description><link>http://ayende.com/blog/4751/uber-prof-new-features-go-to-session-from-alert?key=b28db449-7214-454f-abbf-7eaf960a299a</link><guid>http://ayende.com/blog/4751/uber-prof-new-features-go-to-session-from-alert?key=b28db449-7214-454f-abbf-7eaf960a299a</guid><pubDate>Fri, 14 Jan 2011 10:00:00 GMT</pubDate></item><item><title>What is Uber Prof’s competitive advantage?</title><description>&lt;blockquote&gt;Originally posted at 11/25/2010&lt;/blockquote&gt;&lt;p&gt;In a &lt;a href="http://ayende.com/Blog/archive/2010/11/24/your-design-should-be-focused-on-your-competitive-advantage.aspx"&gt;recent post&lt;/a&gt;, I discussed the notion of competitive advantage and how you should play around them. In this post, I am going to focus on Uber Prof. Just to clarify, when I am talking about Uber Prof, I am talking about &lt;a href="http://nhprof.com/"&gt;NHibernate Profiler&lt;/a&gt;, &lt;a href="http://efprof.com/"&gt;Entity Framework Profiler&lt;/a&gt;, &lt;a href="http://l2sprof.com/"&gt;Linq to SQL Profiler&lt;/a&gt;, &lt;a href="http://hibernateprofiler.com/"&gt;Hibernate Profiler&lt;/a&gt; and &lt;a href="http://llblgenprof.com/"&gt;LLBLGen Profiler&lt;/a&gt;. Uber Prof is just a handle for me to use to talk about each of those.&lt;/p&gt;  &lt;p&gt;So, what is the major competitive advantage that I see in the Uber Prof line of products?&lt;/p&gt;  &lt;p&gt;Put very simply, they focus very heavily on the developer’s point of view. &lt;/p&gt;  &lt;p&gt;Other profilers will give you the SQL that is being executed, but Uber Prof will show you the SQL and:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Format that SQL in a way that make it easy to read.&lt;/li&gt;    &lt;li&gt;Group the SQL statements into sessions. Which let the developer look at what is going on in the natural boundary.&lt;/li&gt;    &lt;li&gt;Associate each query with the exact line of code that executed it.&lt;/li&gt;    &lt;li&gt;Provide the developer with guidance about improving their code.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;There are other stuff, of course, but those are the core features that make Uber Prof into what it is.&lt;/p&gt;</description><link>http://ayende.com/blog/4705/what-is-uber-profs-competitive-advantage?key=6dca10eb-7243-4817-8756-300adfc29ee8</link><guid>http://ayende.com/blog/4705/what-is-uber-profs-competitive-advantage?key=6dca10eb-7243-4817-8756-300adfc29ee8</guid><pubDate>Sat, 27 Nov 2010 10:00:00 GMT</pubDate></item><item><title>Profiler new features: Data binding alerts</title><description>&lt;p&gt;The following features apply to &lt;a href="http://nhprof.com/"&gt;NHProf&lt;/a&gt;, &lt;a href="http://efprof.com/"&gt;EFProf&lt;/a&gt;, &lt;a href="http://l2sprof.com/"&gt;L2SProf&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;In general, it is strong discouraged to data bind directly to an IQueryable. Mostly, that is because data binding may actually iterate over the IQueryable several times, resulting in multiple queries being generated from something that can be done purely in memory. Worse, it is actually pretty common for data binding to result in lazy loading, and lazy loading from data binding almost always result in SELECT N+1. The profiler can now detect and warn you about such mistakes preemptively. More than that, the profiler can also now detect queries that are being generated from the views in an ASP.Net MVC application, another bad practice that I don’t like.&lt;/p&gt;  &lt;p&gt;You can find more information about each warnings here:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://efprof.com/learn/alerts/DataBindingQueries"&gt;Data Binding &amp;amp; Queries Shouldn’t Mix&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://l2sprof.com/learn/alerts/QueriesFromViews"&gt;Don’t Query From The View&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;WPF detection:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesDatabindingalerts_918F/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesDatabindingalerts_918F/image_thumb.png" width="448" height="120" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p /&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesDatabindingalerts_918F/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesDatabindingalerts_918F/image_thumb_1.png" width="751" height="205" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;WinForms detections:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesDatabindingalerts_918F/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesDatabindingalerts_918F/image_thumb_3.png" width="563" height="151" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesDatabindingalerts_918F/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesDatabindingalerts_918F/image_thumb_2.png" width="733" height="197" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Web applications:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesDatabindingalerts_918F/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesDatabindingalerts_918F/image_thumb_4.png" width="581" height="189" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesDatabindingalerts_918F/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesDatabindingalerts_918F/image_thumb_5.png" width="743" height="210" /&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://ayende.com/blog/4642/profiler-new-features-data-binding-alerts?key=d2ea3054-7db3-4e3f-b221-1d71b53d7aef</link><guid>http://ayende.com/blog/4642/profiler-new-features-data-binding-alerts?key=d2ea3054-7db3-4e3f-b221-1d71b53d7aef</guid><pubDate>Mon, 27 Sep 2010 10:00:00 GMT</pubDate></item><item><title>Entity Framework: If you pass a connection to the context, you are responsible for disposing it</title><description>&lt;p&gt;I recently got a bug report about an issue with &lt;a href="http://efprof.com"&gt;EF Prof&lt;/a&gt;, apparently the application statistics would record the context being opened, but it wouldn’t show them being closed. The customer was rightfully worried about that, and wanted to know if this is a bug in his code or in EF Prof.&lt;/p&gt;  &lt;p&gt;Not closing connections is a pretty bad idea, obviously, because you are going to hold a lot more server resources than you need.&lt;/p&gt;  &lt;p&gt;But we couldn’t figure out what the problem was. On my end, I could see that EF Prof was recording the context close properly, but nearly the same code on the customer showed the problem. Note the word &lt;em&gt;nearly&lt;/em&gt;. I asked for a repro of the issue, and once I had it, it took mere minutes to confirm that the problem exists.&lt;/p&gt;  &lt;p&gt;Now was the time to find out &lt;em&gt;why&lt;/em&gt;. The customer code was:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt;(var context = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyContext(&lt;span class="kwrd"&gt;new&lt;/span&gt; EntityConnection(&lt;span class="str"&gt;"name=MyConStr"&lt;/span&gt;))
{
   &lt;span class="rem"&gt;// do stuff&lt;/span&gt;
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;Now, what EF Prof tells you is a data context open &amp;amp; close are actually more accurately connection open &amp;amp; close. After some extensive study, I verified that it wasn’t my code to blame, there was a leaking connection here.&lt;/p&gt;

&lt;p&gt;Checking a bit further, it became clear. We passed an existing connection to the context. When we dispose the context, the context asks: “Am I the owner of this connection?” And since the answer is no, it will &lt;strong&gt;&lt;em&gt;not&lt;/em&gt;&lt;/strong&gt; dispose it. It makes sense, you might want to use that connection for your own purposes, and it is pretty rude of the context to close a connection that it doesn’t own.&lt;/p&gt;

&lt;p&gt;How can we resolve this? By giving the context the information to open the connection, but not the connection itself:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt;(var context = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyContext(&lt;span class="str"&gt;"name=MyConStr"&lt;/span&gt;)
{
   &lt;span class="rem"&gt;// do stuff&lt;/span&gt;
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;This code will instruct the context to open its own connection, which it will know that it owns, so it can safely dispose it when it is disposed.&lt;/p&gt;

&lt;p&gt;Look Ma, no leaks!&lt;/p&gt;</description><link>http://ayende.com/blog/4640/entity-framework-if-you-pass-a-connection-to-the-context-you-are-responsible-for-disposing-it?key=bd798dfc-c7ff-4c1b-b7be-9e4745d2f541</link><guid>http://ayende.com/blog/4640/entity-framework-if-you-pass-a-connection-to-the-context-you-are-responsible-for-disposing-it?key=bd798dfc-c7ff-4c1b-b7be-9e4745d2f541</guid><pubDate>Sat, 25 Sep 2010 10:00:00 GMT</pubDate></item><item><title>Profiler new features, Sept Edition</title><description>&lt;p&gt;The following features apply to &lt;a href="http://nhprof.com"&gt;NHProf&lt;/a&gt;, &lt;a href="http://efprof.com"&gt;EFProf&lt;/a&gt;, &lt;a href="http://hibernateprofiler.com"&gt;HProf&lt;/a&gt;, &lt;a href="http://l2sprof.com"&gt;L2SProf&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The first feature is something that was frequently requested, but we kept deferring. Not because it was hard, but because it was tedious and we had cooler features to implement: Sorting.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesSeptEdition_8A71/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesSeptEdition_8A71/image_thumb.png" width="681" height="135" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Yep. Plain old sorting for all the grids in the application.&lt;/p&gt;  &lt;p&gt;Not an exciting feature, I’ll admit, but an important one.&lt;/p&gt;  &lt;p&gt;The feature that gets &lt;em&gt;me&lt;/em&gt; exciting is the Go To Session. Let us take the Expensive Queries report as a great example for this feature:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesSeptEdition_8A71/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesSeptEdition_8A71/image_thumb_2.png" width="609" height="136" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As you can see, we have a very expensive query. Let us ignore the &lt;em&gt;reason&lt;/em&gt; it is expensive, and assume that we aren’t sure about that.&lt;/p&gt;  &lt;p&gt;The problem with the reports feature in the profiler is that while it exposes a lot of information (expensive queries, most common queries, etc), it also lose the context of where this query is running. That is why you can, in any of the reports, right click on a statement and go directly to the session where it originated from:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesSeptEdition_8A71/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesSeptEdition_8A71/image_thumb_3.png" width="538" height="122" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesSeptEdition_8A71/image_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesSeptEdition_8A71/image_thumb_4.png" width="578" height="149" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We bring the context back to the intelligence that we provide.&lt;/p&gt;  &lt;p&gt;What happen if we have a statement that appear in several sessions?&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesSeptEdition_8A71/image_12.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilernewfeaturesSeptEdition_8A71/image_thumb_5.png" width="480" height="219" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p /&gt;  &lt;p&gt;You can select each session that this statement appears in, getting back the context of the statement and finding out a lot more about it.&lt;/p&gt;  &lt;p&gt;I am very happy about this feature, because I think that it closes a circle with regards to the reports. The reports allows you to pull out a lot of data across you entire application, and the Go To Session feature allows you to connect the interesting pieces of the data back to originating session, giving you where and why this statement was issued.&lt;/p&gt;</description><link>http://ayende.com/blog/4632/profiler-new-features-sept-edition?key=ea32c80b-9b96-4fd8-8d41-6c8131c017fa</link><guid>http://ayende.com/blog/4632/profiler-new-features-sept-edition?key=ea32c80b-9b96-4fd8-8d41-6c8131c017fa</guid><pubDate>Fri, 17 Sep 2010 11:00:00 GMT</pubDate></item><item><title>Estimates sucks, especially when I pay for them</title><description>&lt;p&gt;I recently got an estimate for a feature that I wanted to add to &lt;a href="http://nhprof.com"&gt;NH Prof&lt;/a&gt;. It was for two separate features, actually, but they were closely related. &lt;/p&gt;  &lt;p&gt;That estimate was for 32 hours. &lt;/p&gt;  &lt;p&gt;And it caused me a great deal of indigestion. The problem was, quite simply, that even granting that there is the usual padding of estimates (which I expect), that timing estimate was off, &lt;em&gt;way&lt;/em&gt; off. I knew what would be required for this feature, and it shouldn’t be anywhere &lt;em&gt;near&lt;/em&gt; complicated enough to require 4 days of full time work. In fact, I estimated that it would take me a maximum of 6 hours and a probable of 3 hours to get it done.&lt;/p&gt;  &lt;p&gt;Now, to be fair, I &lt;em&gt;know&lt;/em&gt; the codebase (well, actually that isn’t true, a lot of the code for NH Prof was written by &lt;a href="http://devlicio.us/blogs/rob_eisenberg/"&gt;Rob&lt;/a&gt; &amp;amp; &lt;a href="http://devlicious.com/blogs/christopher_bennage/"&gt;Christopher&lt;/a&gt;, and after a few days of working with them, I stopped looking at the code, there wasn’t any need to do so). And I am well aware that most people consider me to be an above average developer. &lt;/p&gt;  &lt;p&gt;I wouldn’t have batted an eye for an estimate of 8 – 14 hours, probably. Part of the reason that I have other people working on the code base is that even though I can do certain things faster, I can only do so many things, after all.&lt;/p&gt;  &lt;p&gt;But a time estimate that was 5 – 10 times as large as what I estimated was too annoying. I decided that &lt;em&gt;this&lt;/em&gt; feature I am going to do on my own. And I decided that I wanted to do this on the clock.&lt;/p&gt;  &lt;p&gt;The result is here:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/EstimatessucksespeciallywhenIpayforthem_117BA/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/EstimatessucksespeciallywhenIpayforthem_117BA/image_thumb.png" width="471" height="193" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This is actually total time over three separate sittings, but the timing is close enough to what I though it would be.&lt;/p&gt;  &lt;p&gt;This includes &lt;em&gt;everything&lt;/em&gt;, implementing the feature, unit testing it, wiring it up in the UI, etc.&lt;/p&gt;  &lt;p&gt;The only thing remaining is to add the UI works for the other profilers (&lt;a href="http://efprof.com"&gt;Entity Framework&lt;/a&gt;, &lt;a href="http://l2sprof.com"&gt;Linq to SQL&lt;/a&gt;, &lt;a href="http://hibernateprofiler.com"&gt;Hibernate&lt;/a&gt; and the upcoming LLBLGen Profiler) . Doing this now…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/EstimatessucksespeciallywhenIpayforthem_117BA/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/EstimatessucksespeciallywhenIpayforthem_117BA/image_thumb_1.png" width="438" height="191" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;And we are done.&lt;/p&gt;  &lt;p&gt;I have more features that I want to implement, but in general, if I pushed those changes out, they would be a new release that customers can use immediately.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nitpicker corner:&lt;/b&gt; No, I am not being ripped off. And no, the people making the estimates aren't incompetent. To be perfectly honest, looking at the work that they did do and the time marked against it, they are good, and they deliver in a reasonable time frame. What I think is going on is that their estimates are &lt;i&gt;highly&lt;/i&gt; conservative, because they don't want to get into a bind with "oh, we run into a problem with XYZ and overrun the time for the feature by 150%".&lt;/p&gt;
&lt;p&gt;That also lead to a different problem, when you pay by the hour, you really want to have estimates that are more or less reasonably tied to your payments. But estimating with hours has too much granularity to be really effective (a single bug can easily consume hours, totally throwing off estimation, and it doesn't even have to be a complex one.)&lt;/p&gt;</description><link>http://ayende.com/blog/4627/estimates-sucks-especially-when-i-pay-for-them?key=c6294703-532a-4dee-b64c-ebef996a595f</link><guid>http://ayende.com/blog/4627/estimates-sucks-especially-when-i-pay-for-them?key=c6294703-532a-4dee-b64c-ebef996a595f</guid><pubDate>Sun, 12 Sep 2010 10:00:00 GMT</pubDate></item><item><title>The Profiler New Features: Starring &amp; Renaming</title><description>&lt;p&gt;An interesting thing happened recently, when I started to build the profiler, a lot of the features were what I call Core Features. Those were the things that without which, we wouldn’t &lt;em&gt;have&lt;/em&gt; a product. Things like detecting SQL, merging it into sessions, providing reports, etc. What I find myself doing recently with the profiler is not so much building Core Features, but building UX features. In other words, now that we have this in place, let us see how we can make better use of this. &lt;/p&gt;  &lt;p&gt;Case in point, the new features that were just released in build 713. They aren’t big, but they are there to improve how people are commonly using the products.&lt;/p&gt;  &lt;p&gt;Renaming a session:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/TheProfilerNewFeaturesStarringRenaming_A482/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/TheProfilerNewFeaturesStarringRenaming_A482/image_thumb.png" width="357" height="237" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This is primarily useful if you are in a long profiling session and you want to mark a specific session with some notation:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/TheProfilerNewFeaturesStarringRenaming_A482/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/TheProfilerNewFeaturesStarringRenaming_A482/image_thumb_1.png" width="460" height="172" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p /&gt;  &lt;p&gt;Small feature, and individually not very useful. But you might have noticed that the sessions are marked with stars around them. They weren’t there is previous builds, so what are they?&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/TheProfilerNewFeaturesStarringRenaming_A482/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/TheProfilerNewFeaturesStarringRenaming_A482/image_thumb_2.png" width="369" height="174" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;They are a way to tell the profiler that you really like those sessions :-)&lt;/p&gt;  &lt;p&gt;More to the point, such sessions will not be removed when you clear the current state. That lets you keep around the previous state of the application as a base line while you work to improve it. Beside, it makes it much easier to locate them visually.&lt;/p&gt;  &lt;p&gt;And finally, as a quicker way to do that, you can just ask the profiler to clear all but the selected features.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/TheProfilerNewFeaturesStarringRenaming_A482/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/TheProfilerNewFeaturesStarringRenaming_A482/image_thumb_3.png" width="396" height="241" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Not big features, but nice ones, I think.&lt;/p&gt;</description><link>http://ayende.com/blog/4608/the-profiler-new-features-starring-renaming?key=18646a6f-4599-4c3a-8765-575af7ce061b</link><guid>http://ayende.com/blog/4608/the-profiler-new-features-starring-renaming?key=18646a6f-4599-4c3a-8765-575af7ce061b</guid><pubDate>Thu, 26 Aug 2010 08:13:00 GMT</pubDate></item><item><title>Analyzing LightSwitch data access behavior</title><description>&lt;p&gt;I thought it would be a good idea to see what sort of data access behavior LightSwitch applications have. So I hook it up with the &lt;a href="http://ayende.com/Blog/archive/2010/08/25/profiling-lightswitch-using-entity-framework-profiler.aspx"&gt;EntityFramework Profiler&lt;/a&gt; and took it for a spin.&lt;/p&gt;  &lt;p&gt;It is interesting to note that it seems that every operation that is running is running in the context of a distributed transaction:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_thumb.png" width="557" height="44" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;There is a time &amp;amp; place to use DTC, but in general, you should avoid them until you really need them. I assume that this is something that is actually being triggered by WCF behavior, not intentional.&lt;/p&gt;  &lt;p&gt;Now, let us look at what a simple search looks like:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_thumb_1.png" width="571" height="205" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This search results in:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_thumb_2.png" width="506" height="465" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;That sound? Yes, the one that you just heard. That is the sound of a DBA somewhere expiring. The presentation about LightSwitch touted how you can search every field. And you certainly can. You can also swim across the English channel, but I found that taking the train seems to be an easier way to go about doing this. &lt;/p&gt;  &lt;p&gt;Doing this sort of searching is going to be:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Very expensive once you have any reasonable amount of data.&lt;/li&gt;    &lt;li&gt;Prevent usage of indexes to optimize performance.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In other words, this is an extremely brute force approach for this, and it is going to be pretty bad from performance perspective.&lt;/p&gt;  &lt;p&gt;Interestingly, it seems that LS is using optimistic concurrency by default. &lt;/p&gt;  &lt;p /&gt;  &lt;p /&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_thumb_4.png" width="506" height="178" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I wonder why they use the slowest method possible for this, instead of using version numbers.&lt;/p&gt;  &lt;p&gt;Now, let see how it handles references. I think that I run into something which is a problem, consider:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_12.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_thumb_5.png" width="509" height="553" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Which generates:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_14.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_thumb_6.png" width="836" height="290" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This make sense only if you can think of the underlying data model. It certainly seems backward to me.&lt;/p&gt;  &lt;p&gt;I fixed that, and created four animals, each as the parent of the other:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_18.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_thumb_8.png" width="468" height="414" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Which is nice, except that here is the SQL required to generate this screen:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;-- statement #1&lt;/span&gt;
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; [GroupBy1].[A1] &lt;span class="kwrd"&gt;AS&lt;/span&gt; [C1]
&lt;span class="kwrd"&gt;FROM&lt;/span&gt;   (&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; &lt;span class="kwrd"&gt;COUNT&lt;/span&gt;(1) &lt;span class="kwrd"&gt;AS&lt;/span&gt; [A1]
        &lt;span class="kwrd"&gt;FROM&lt;/span&gt;   [dbo].[AnimalsSet] &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Extent1]) &lt;span class="kwrd"&gt;AS&lt;/span&gt; [GroupBy1]

&lt;span class="rem"&gt;-- statement #2&lt;/span&gt;
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt;   &lt;span class="kwrd"&gt;TOP&lt;/span&gt; ( 45 ) [Extent1].[Id]              &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Id],
                    [Extent1].[Name]            &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Name],
                    [Extent1].[DateOfBirth]     &lt;span class="kwrd"&gt;AS&lt;/span&gt; [DateOfBirth],
                    [Extent1].[Species]         &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Species],
                    [Extent1].[Color]           &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Color],
                    [Extent1].[Pic]             &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Pic],
                    [Extent1].[Animals_Animals] &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Animals_Animals]
&lt;span class="kwrd"&gt;FROM&lt;/span&gt;     (&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; [Extent1].[Id]                      &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Id],
                 [Extent1].[Name]                    &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Name],
                 [Extent1].[DateOfBirth]             &lt;span class="kwrd"&gt;AS&lt;/span&gt; [DateOfBirth],
                 [Extent1].[Species]                 &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Species],
                 [Extent1].[Color]                   &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Color],
                 [Extent1].[Pic]                     &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Pic],
                 [Extent1].[Animals_Animals]         &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Animals_Animals],
                 row_number()
                   &lt;span class="kwrd"&gt;OVER&lt;/span&gt;(&lt;span class="kwrd"&gt;ORDER&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; [Extent1].[Id] &lt;span class="kwrd"&gt;ASC&lt;/span&gt;) &lt;span class="kwrd"&gt;AS&lt;/span&gt; [row_number]
          &lt;span class="kwrd"&gt;FROM&lt;/span&gt;   [dbo].[AnimalsSet] &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Extent1]) &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Extent1]
&lt;span class="kwrd"&gt;WHERE&lt;/span&gt;    [Extent1].[row_number] &amp;gt; 0
&lt;span class="kwrd"&gt;ORDER&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt; [Extent1].[Id] &lt;span class="kwrd"&gt;ASC&lt;/span&gt;

&lt;span class="rem"&gt;-- statement #3&lt;/span&gt;
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; [Extent1].[Id]              &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Id],
       [Extent1].[Name]            &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Name],
       [Extent1].[DateOfBirth]     &lt;span class="kwrd"&gt;AS&lt;/span&gt; [DateOfBirth],
       [Extent1].[Species]         &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Species],
       [Extent1].[Color]           &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Color],
       [Extent1].[Pic]             &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Pic],
       [Extent1].[Animals_Animals] &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Animals_Animals]
&lt;span class="kwrd"&gt;FROM&lt;/span&gt;   [dbo].[AnimalsSet] &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Extent1]
&lt;span class="kwrd"&gt;WHERE&lt;/span&gt;  1 = [Extent1].[Id]

&lt;span class="rem"&gt;-- statement #4&lt;/span&gt;
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; [Extent1].[Id]              &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Id],
       [Extent1].[Name]            &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Name],
       [Extent1].[DateOfBirth]     &lt;span class="kwrd"&gt;AS&lt;/span&gt; [DateOfBirth],
       [Extent1].[Species]         &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Species],
       [Extent1].[Color]           &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Color],
       [Extent1].[Pic]             &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Pic],
       [Extent1].[Animals_Animals] &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Animals_Animals]
&lt;span class="kwrd"&gt;FROM&lt;/span&gt;   [dbo].[AnimalsSet] &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Extent1]
&lt;span class="kwrd"&gt;WHERE&lt;/span&gt;  2 = [Extent1].[Id]

&lt;span class="rem"&gt;-- statement #5&lt;/span&gt;
&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; [Extent1].[Id]              &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Id],
       [Extent1].[Name]            &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Name],
       [Extent1].[DateOfBirth]     &lt;span class="kwrd"&gt;AS&lt;/span&gt; [DateOfBirth],
       [Extent1].[Species]         &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Species],
       [Extent1].[Color]           &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Color],
       [Extent1].[Pic]             &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Pic],
       [Extent1].[Animals_Animals] &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Animals_Animals]
&lt;span class="kwrd"&gt;FROM&lt;/span&gt;   [dbo].[AnimalsSet] &lt;span class="kwrd"&gt;AS&lt;/span&gt; [Extent1]
&lt;span class="kwrd"&gt;WHERE&lt;/span&gt;  3 = [Extent1].[Id]&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;I &lt;em&gt;told&lt;/em&gt; you that there is a &lt;em&gt;select n+1&lt;/em&gt; builtin into the product, now didn’t I?&lt;/p&gt;

&lt;p&gt;Now, to make things just that much worse, it isn’t actually a Select N+1 that you’ll easily recognize. because this doesn’t happen on a single request. Instead, we have a multi tier Select N+1.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_20.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/AnalyzingLightSwitchdataaccessbehavior_8235/image_thumb_9.png" width="1048" height="86" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;What is actually happening is that in this case, we make the first request to get the data, then we make an additional web request &lt;em&gt;per returned result&lt;/em&gt; to get the data about the parent.&lt;/p&gt;

&lt;p&gt;And I think that you’ll have to admit that a Parent-&amp;gt;&amp;gt;Children association isn’t something that is out of the ordinary. In typical system, where you may have many associations, this “feature” alone is going to slow the system to a crawl.&lt;/p&gt;</description><link>http://ayende.com/blog/4605/analyzing-lightswitch-data-access-behavior?key=6de45544-8bb4-414b-b436-bee4df495cbd</link><guid>http://ayende.com/blog/4605/analyzing-lightswitch-data-access-behavior?key=6de45544-8bb4-414b-b436-bee4df495cbd</guid><pubDate>Wed, 25 Aug 2010 05:34:00 GMT</pubDate></item><item><title>Profiling LightSwitch using Entity Framework Profiler</title><description>&lt;p&gt;This post is to help everyone who want to understand what LightSwitch is going to do under the covers. It allows you to see exactly what is going on with the database interaction using &lt;a href="http://efprof.com"&gt;Entity Framework Profiler&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;In your LightSwitch application, switch to file view:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilingLightSwitchusingEntityFramework_785F/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilingLightSwitchusingEntityFramework_785F/image_thumb.png" width="244" height="89" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;In the server project, add a reference to HibernatingRhinos.Profiler.Appender.v4.0, which you can find in the EF Prof download.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilingLightSwitchusingEntityFramework_785F/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilingLightSwitchusingEntityFramework_785F/image_thumb_1.png" width="334" height="73" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Open the ApplicationDataService file inside the UserCode directory:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilingLightSwitchusingEntityFramework_785F/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilingLightSwitchusingEntityFramework_785F/image_thumb_2.png" width="244" height="163" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Add a static constructor with a call to initialize the entity framework profiler:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ApplicationDataService
{
    &lt;span class="kwrd"&gt;static&lt;/span&gt; ApplicationDataService()
    {
        HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();
    }
}&lt;/pre&gt;

&lt;p&gt;This is it!&lt;/p&gt;

&lt;p&gt;You’re now able to work with the &lt;a href="http://efprof.com"&gt;Entity Framework Profiler&lt;/a&gt; and see what sort of queries are being generated on your behalf.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilingLightSwitchusingEntityFramework_785F/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/ProfilingLightSwitchusingEntityFramework_785F/image_thumb_3.png" width="1024" height="768" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;</description><link>http://ayende.com/blog/4604/profiling-lightswitch-using-entity-framework-profiler?key=5fcd2c6d-fea2-4921-9f35-a6ebf2453b6f</link><guid>http://ayende.com/blog/4604/profiling-lightswitch-using-entity-framework-profiler?key=5fcd2c6d-fea2-4921-9f35-a6ebf2453b6f</guid><pubDate>Wed, 25 Aug 2010 05:29:00 GMT</pubDate></item><item><title>Playing with Entity Framework Code Only</title><description>&lt;p&gt;After making &lt;a href="http://efprof.com"&gt;EF Prof&lt;/a&gt; work with EF Code Only, I decided that I might take a look at how Code Only actually work from the perspective of the application developer. I am working on my own solution based on the following posts:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;h5&gt;&lt;a href="http://blogs.msdn.com/b/adonet/archive/2010/07/14/ctp4codefirstwalkthrough.aspx"&gt;EF Feature CTP4 Walkthrough: Code First&lt;/a&gt;&lt;/h5&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;h5&gt;&lt;a href="http://blogs.msdn.com/b/adonet/archive/2010/07/14/ctp4piwalkthrough.aspx"&gt;EF Feature CTP4 Walkthrough: Productivity Improvements&lt;/a&gt;&lt;/h5&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;But since I don’t like to just read things, and I hate walkthroughs, I decided to take that into a slightly different path. In order to do that, I decided to set myself the following goal:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/PlayingwithEntityFrameworkCodeOnly_14462/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="right" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/PlayingwithEntityFrameworkCodeOnly_14462/image_thumb.png" width="619" height="329" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Create a ToDo application with the following entities:&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;User&lt;/li&gt;      &lt;li&gt;Actions (inheritance)&lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;ToDo&lt;/li&gt;        &lt;li&gt;Reminder&lt;/li&gt;     &lt;/ul&gt;   &lt;/ul&gt;    &lt;li&gt;Query for:&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;All actions for user&lt;/li&gt;      &lt;li&gt;All reminders for today across all users&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;That isn’t really a complex system, but my intention is to get to grips with how things work. And see how much friction I encounter along the way.&lt;/p&gt;  &lt;p&gt;We start by referencing “Microsoft.Data.Entity.Ctp” &amp;amp; “System.Data.Entity”&lt;/p&gt;  &lt;p&gt;There appears to be a wide range of options to define how entities should be mapped. This include building them using a fluent interface, creating map classes or auto mapping. All in all, the code shows a remarkable similarity to Fluent NHibernate, in spirit if not in actual API.&lt;/p&gt;  &lt;p&gt;I don’t like some of the API:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;HasRequired and HasKey for example, seems to be awkwardly named to me, especially when they are used as part of a fluent sentence. I have long advocated avoiding the attempt to create real sentences in a fluent API (StructureMap was probably the worst in this regard). Dropping the Has prefix would be just as understandable, and look better, IMO.&lt;/li&gt;    &lt;li&gt;Why do we have both IsRequired and HasRequired? The previous comment apply, with the addition that having two similarly named methods that appears to be doing the same thing is probably not a good idea.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;But aside from that, it appears very nice.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ObjectContext vs. DbContext &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I am not sure why there are two of them, but I have a very big dislike of ObjectContext, the amount of code that you have to write to make it work is just ridiculous, when you compare that to the amount of code you have to write for DbContext.&lt;/p&gt;  &lt;p&gt;I also &lt;em&gt;strongly&lt;/em&gt; dislike the need to pass a DbConnection to the ObjectContext. The actual management of the connection is &lt;em&gt;not&lt;/em&gt; within the scope of the application developer. That is within the scope of the infrastructure. Messing with DbConnection in application code should be left to &lt;em&gt;very&lt;/em&gt; special circumstances and require swearing an oath of nonmaleficence. The DbContext doesn’t require that, so that is another thing that is in favor of it.&lt;/p&gt;  &lt;p&gt;Using the DbContext is nice:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ToDoContext : DbContext
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DbModel model;

    &lt;span class="kwrd"&gt;static&lt;/span&gt; ToDoContext()
    {
        var modelBuilder = &lt;span class="kwrd"&gt;new&lt;/span&gt; ModelBuilder();
        modelBuilder.DiscoverEntitiesFromContext(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ToDoContext));
        modelBuilder.Entity&amp;lt;User&amp;gt;().HasKey(x =&amp;gt; x.Username);
        model = modelBuilder.CreateModel();
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; ToDoContext():&lt;span class="kwrd"&gt;base&lt;/span&gt;(model)
    {
        
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; DbSet&amp;lt;Action&amp;gt; Actions { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; DbSet&amp;lt;User&amp;gt; Users { get; set; }
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;Note that we can mix &amp;amp; match the configuration styles, some are auto mapped, some are explicitly stated. It appears that if you fully follow the builtin conventions, you don’t even &lt;em&gt;need&lt;/em&gt; ModelBuilder, as that will be build for you automatically.&lt;/p&gt;

&lt;p&gt;Let us try to run things:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt;(var ctx = &lt;span class="kwrd"&gt;new&lt;/span&gt; ToDoContext())
{
    ctx.Users.ToList();
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;The connection string is specified in the app.config, by defining a connection string with the name of the context. &lt;/p&gt;

&lt;p&gt;Then I just run it, &lt;em&gt;without creating a database&lt;/em&gt;. I expected it to fail, but it didn’t. Instead, it created the following schema:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/PlayingwithEntityFrameworkCodeOnly_14462/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/PlayingwithEntityFrameworkCodeOnly_14462/image_thumb_1.png" width="491" height="201" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;That is a problem&lt;/strong&gt;, DDL should &lt;em&gt;never&lt;/em&gt; run as an implicit step. I couldn’t figure out how to disable that, though (but I didn’t look &lt;em&gt;too&lt;/em&gt; hard). To be fair, this looks like it will only run if the database doesn’t exists (not only if the tables aren’t there). But I would still make this an explicit step.&lt;/p&gt;

&lt;p&gt;The result of running the code is:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/PlayingwithEntityFrameworkCodeOnly_14462/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/PlayingwithEntityFrameworkCodeOnly_14462/image_thumb_2.png" width="636" height="335" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now the time came to try executing my queries:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;var actionsForUser = 
    (
        from action &lt;span class="kwrd"&gt;in&lt;/span&gt; ctx.Actions
        &lt;span class="kwrd"&gt;where&lt;/span&gt; action.User.Username == &lt;span class="str"&gt;"Ayende"&lt;/span&gt;
        select action
    )
    .ToList();

var remindersForToday =
    (
        from reminder &lt;span class="kwrd"&gt;in&lt;/span&gt; ctx.Actions.OfType&amp;lt;Reminder&amp;gt;()
        &lt;span class="kwrd"&gt;where&lt;/span&gt; reminder.Date == DateTime.Today
        select reminder
    )
    .ToList();&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Which resulted in:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/PlayingwithEntityFrameworkCodeOnly_14462/image_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/PlayingwithEntityFrameworkCodeOnly_14462/image_thumb_4.png" width="532" height="385" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;That has been a pretty brief overview of Entity Framework Code Only, but I am impressed, the whole process has been remarkably friction free, and the time to go from nothing to a working model has been extremely short.&lt;/p&gt;</description><link>http://ayende.com/blog/4583/playing-with-entity-framework-code-only?key=fc311021-fd99-435b-889a-d1edec9f6e8e</link><guid>http://ayende.com/blog/4583/playing-with-entity-framework-code-only?key=fc311021-fd99-435b-889a-d1edec9f6e8e</guid><pubDate>Wed, 11 Aug 2010 09:00:00 GMT</pubDate></item><item><title>EF Prof and Code Only</title><description>&lt;p&gt;I just finish touching up a new feature for &lt;a href="http://efprof.com"&gt;EF Prof&lt;/a&gt;, support for Entity Framework’s Code Only feature. What you see below is EF Prof tracking the &lt;a href="http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx"&gt;Code Only Nerd Dinner&lt;/a&gt; example:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/EFProfandCodeOnly_93F/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/EFProfandCodeOnly_93F/image_thumb.png" width="881" height="535" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I tried to tackle the same thing in CTP3, but I was unable to resolve it. Using CTP4, it was about as easy as I could wish it.&lt;/p&gt;  &lt;p&gt;Just for fun, the following screen shot looks like it contains a bug, but it doesn’t (at least, not to my knowledge). If you can spot what the bug is, I am going to hand you a 25% discount coupon for EF Prof. If you can tell me why it is &lt;em&gt;not &lt;/em&gt;a bug, I would double that.&lt;/p&gt;  &lt;p&gt;As an aside, am I the only one that is bothered by the use of @@IDNETITY by EF? I thought that we weren’t supposed to make use of that. Moreover, why write this complex statement when you can write SELECT @@IDENTITY?&lt;/p&gt;</description><link>http://ayende.com/blog/4566/ef-prof-and-code-only?key=42005397-c4b9-4a63-881f-d48793b34481</link><guid>http://ayende.com/blog/4566/ef-prof-and-code-only?key=42005397-c4b9-4a63-881f-d48793b34481</guid><pubDate>Thu, 29 Jul 2010 21:39:00 GMT</pubDate></item></channel></rss>
