<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>My view on C#</title>
	<atom:link href="https://ilmatte.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://ilmatte.wordpress.com</link>
	<description>Just another C# weblog</description>
	<lastBuildDate>Thu, 04 Oct 2018 19:47:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<site xmlns="com-wordpress:feed-additions:1">2402635</site><cloud domain='ilmatte.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://s0.wp.com/i/buttonw-com.png</url>
		<title>My view on C#</title>
		<link>https://ilmatte.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://ilmatte.wordpress.com/osd.xml" title="My view on C#" />
	<atom:link rel='hub' href='https://ilmatte.wordpress.com/?pushpress=hub'/>
	<item>
		<title>No Part-Time Product Owner</title>
		<link>https://ilmatte.wordpress.com/2017/02/19/no-part-time-product-owner/</link>
					<comments>https://ilmatte.wordpress.com/2017/02/19/no-part-time-product-owner/#comments</comments>
		
		<dc:creator><![CDATA[ilmatte]]></dc:creator>
		<pubDate>Sun, 19 Feb 2017 20:36:16 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=730</guid>

					<description><![CDATA[The dark side of not investing in a product owner Article originally published at www.scrumalliance.org. You can find the original article here. Let me tell you about my experience working without a true product owner. At my company, we all heard that implementing some of the Scrum practices didn&#8217;t mean that we were implementing Scrum. We [&#8230;]]]></description>
										<content:encoded><![CDATA[<h3><span style="background-color:#eeeeee;">The dark side of not investing in a product owner</span></h3>
<p><i>Article originally published at <a href="http://www.scrumalliance.org/" target="_blank">www.scrumalliance.org</a>.<br />
You can find the original article <a href="https://www.scrumalliance.org/community/articles/2017/january/no-part-time-product-owner" target="_blank">here</a>.</i></p>
<p><i></i><br />
Let me tell you about my experience working without a true product owner. At my company, we all heard that implementing some of the Scrum practices didn&#8217;t mean that we were implementing Scrum. We also learned that the only way to win stakeholders&#8217; approval was to run a few sprints and let the product speak for itself.</p>
<p>That&#8217;s all well and good, but be careful. In fact, I think your team should ask itself what it will be able to do in those few sprints if the stakeholders are not convinced at all about Scrum. Of course, you can start with a training session for businesspeople who are new to the Scrum framework. This is exactly what we did, in the hope of guaranteeing a common background to build upon. The problem is that after the initial training sessions, you either win or lose the customer. And if you lose the customer, what you get is something like, &#8220;OK, that’s great! Feel free to do that Scrum thing in the IT department, and deploy new features every two weeks.&#8221;</p>
<p>This doesn’t feel like your business manager considers herself really involved in the process! Actually, it feels like there’s a lack of understanding the basics of what we’re talking about. But that’s just it — it&#8217;s a seismic change in mindset that occurs over time. In our case, this perception had not been pronounced explicitly in this flavor, but the meaning of all our talking and compromises sounded very much like it.<br />
<em>You can read the full article here: </em><a href="http://myviewonsoftwaredevelopment.blogspot.it/2017/02/no-part-time-product-owner.html" target="_blank">No Part-Time Product Owner</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://ilmatte.wordpress.com/2017/02/19/no-part-time-product-owner/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">730</post-id>
		<media:content url="https://0.gravatar.com/avatar/9b6dfe5bd4ef55adc68d6b8a3127bb384d6c8eb25356dfe4fb2bb050e9145f8d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>
	</item>
		<item>
		<title>Quickly setup Android Studio with Git and Bitbucket</title>
		<link>https://ilmatte.wordpress.com/2016/02/15/quickly-setup-android-studio-with-git-and-bitbucket/</link>
					<comments>https://ilmatte.wordpress.com/2016/02/15/quickly-setup-android-studio-with-git-and-bitbucket/#respond</comments>
		
		<dc:creator><![CDATA[ilmatte]]></dc:creator>
		<pubDate>Mon, 15 Feb 2016 20:57:33 +0000</pubDate>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Bitbucket]]></category>
		<category><![CDATA[Git]]></category>
		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=728</guid>

					<description><![CDATA[This post is no longer maintained. Click here for the updated version of this post]]></description>
										<content:encoded><![CDATA[<h1><span style="color:#3366ff;"><a title="linktorevisedpost" href="http://theworkingdad.it/en/2018/10/04/quickly-setup-android-studio-with-git-and-bitbucket/" name="linktorevisedpost">This post is no longer maintained. Click here for the updated version of this post</a></span></h1>
]]></content:encoded>
					
					<wfw:commentRss>https://ilmatte.wordpress.com/2016/02/15/quickly-setup-android-studio-with-git-and-bitbucket/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">728</post-id>
		<media:content url="https://0.gravatar.com/avatar/9b6dfe5bd4ef55adc68d6b8a3127bb384d6c8eb25356dfe4fb2bb050e9145f8d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>
	</item>
		<item>
		<title>IIS Express GUI and Visual Studio 2010 integration</title>
		<link>https://ilmatte.wordpress.com/2013/06/06/iis-express-gui-and-visual-studio-2010-integration/</link>
					<comments>https://ilmatte.wordpress.com/2013/06/06/iis-express-gui-and-visual-studio-2010-integration/#comments</comments>
		
		<dc:creator><![CDATA[ilmatte]]></dc:creator>
		<pubDate>Thu, 06 Jun 2013 21:47:01 +0000</pubDate>
				<category><![CDATA[IIS Express]]></category>
		<category><![CDATA[VisualStudio]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WPF]]></category>
		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=718</guid>

					<description><![CDATA[This post is no longer maintained. Click here for the updated version of this post]]></description>
										<content:encoded><![CDATA[<h1><span style="color:#3366ff;"><a title="linktorevisedpost" href="http://theworkingdad.it/en/2018/10/04/iis-express-gui-and-visual-studio-2010-integration/" name="linktorevisedpost">This post is no longer maintained. Click here for the updated version of this post</a></span></h1>
]]></content:encoded>
					
					<wfw:commentRss>https://ilmatte.wordpress.com/2013/06/06/iis-express-gui-and-visual-studio-2010-integration/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">718</post-id>
		<media:content url="https://0.gravatar.com/avatar/9b6dfe5bd4ef55adc68d6b8a3127bb384d6c8eb25356dfe4fb2bb050e9145f8d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting up Git With Visual Studio Tutorial</title>
		<link>https://ilmatte.wordpress.com/2013/02/12/setting-up-git-with-visual-studio-tutorial/</link>
					<comments>https://ilmatte.wordpress.com/2013/02/12/setting-up-git-with-visual-studio-tutorial/#comments</comments>
		
		<dc:creator><![CDATA[ilmatte]]></dc:creator>
		<pubDate>Tue, 12 Feb 2013 19:27:38 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[VisualStudio]]></category>
		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=647</guid>

					<description><![CDATA[This post is no longer maintained. Click here for the updated version of this post]]></description>
										<content:encoded><![CDATA[<h1><span style="color:#3366ff;"><a title="linktorevisedpost" href="http://theworkingdad.it/en/2018/10/03/setting-up-git-with-visual-studio-tutorial/" name="linktorevisedpost">This post is no longer maintained. Click here for the updated version of this post</a></span></h1>
]]></content:encoded>
					
					<wfw:commentRss>https://ilmatte.wordpress.com/2013/02/12/setting-up-git-with-visual-studio-tutorial/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">647</post-id>
		<media:content url="https://0.gravatar.com/avatar/9b6dfe5bd4ef55adc68d6b8a3127bb384d6c8eb25356dfe4fb2bb050e9145f8d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>
	</item>
		<item>
		<title>Entity Framework: Joining in memory data with DbSet</title>
		<link>https://ilmatte.wordpress.com/2013/01/06/entity-framework-joining-in-memory-data-with-dbset/</link>
					<comments>https://ilmatte.wordpress.com/2013/01/06/entity-framework-joining-in-memory-data-with-dbset/#comments</comments>
		
		<dc:creator><![CDATA[ilmatte]]></dc:creator>
		<pubDate>Sun, 06 Jan 2013 17:22:18 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Code First]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Queryable]]></category>
		<category><![CDATA[In-Memory Collection]]></category>
		<category><![CDATA[Linq Join]]></category>
		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=634</guid>

					<description><![CDATA[This post is no longer maintained. Click here for the updated version of this post]]></description>
										<content:encoded><![CDATA[<h1><span style="color:#3366ff;"><a title="linktorevisedpost" href="http://theworkingdad.it/en/2018/10/03/entity-framework-joining-in-memory-data-with-dbset/" name="linktorevisedpost">This post is no longer maintained. Click here for the updated version of this post</a></span></h1>
]]></content:encoded>
					
					<wfw:commentRss>https://ilmatte.wordpress.com/2013/01/06/entity-framework-joining-in-memory-data-with-dbset/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">634</post-id>
		<media:content url="https://0.gravatar.com/avatar/9b6dfe5bd4ef55adc68d6b8a3127bb384d6c8eb25356dfe4fb2bb050e9145f8d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>
	</item>
		<item>
		<title>Entity Framework Code First: Always disable AutoDetectChanges when importing data</title>
		<link>https://ilmatte.wordpress.com/2013/01/01/entity-framework-code-first-always-disable-autodetectchanges-when-importing-data/</link>
					<comments>https://ilmatte.wordpress.com/2013/01/01/entity-framework-code-first-always-disable-autodetectchanges-when-importing-data/#comments</comments>
		
		<dc:creator><![CDATA[ilmatte]]></dc:creator>
		<pubDate>Tue, 01 Jan 2013 16:50:46 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Code First]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[AutoDetectChanges]]></category>
		<category><![CDATA[Performance]]></category>
		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=624</guid>

					<description><![CDATA[This post is no longer maintained. Click here for the updated version of this post &#160;]]></description>
										<content:encoded><![CDATA[<h1><span style="color:#3366ff;"><a title="linktorevisedpost" href="http://theworkingdad.it/en/2018/10/03/entity-framework-code-first-always-disable-autodetectchanges-when-importing-data/" name="linktorevisedpost">This post is no longer maintained. Click here for the updated version of this post</a></span></h1>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ilmatte.wordpress.com/2013/01/01/entity-framework-code-first-always-disable-autodetectchanges-when-importing-data/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">624</post-id>
		<media:content url="https://0.gravatar.com/avatar/9b6dfe5bd4ef55adc68d6b8a3127bb384d6c8eb25356dfe4fb2bb050e9145f8d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>
	</item>
		<item>
		<title>Linq To Entities: Queryable.Sum returns Null on an empty list</title>
		<link>https://ilmatte.wordpress.com/2012/12/20/queryable-sum-on-decimal-and-null-return-value-with-linq-to-entities/</link>
					<comments>https://ilmatte.wordpress.com/2012/12/20/queryable-sum-on-decimal-and-null-return-value-with-linq-to-entities/#comments</comments>
		
		<dc:creator><![CDATA[ilmatte]]></dc:creator>
		<pubDate>Thu, 20 Dec 2012 22:48:05 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Queryable]]></category>
		<category><![CDATA[extension methods]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[Queryable.Sum]]></category>
		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=612</guid>

					<description><![CDATA[This post is no longer maintained. Click here for the updated version of this post income.Amount); } } catch (Exception exception) { Console.WriteLine(exception.ToString()); } [/sourcecode] If you run this code on an empty table you will get the following exception: In my example I suppose that you already used Entity Framework Code First. I explicitly [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1><span style="color:#3366ff;"><a title="linktorevisedpost" href="http://theworkingdad.it/en/2018/10/02/linq-to-entities-queryable-sum-returns-null-on-an-empty-list/" name="linktorevisedpost">This post is no longer maintained. Click here for the updated version of this post</a></span></h1>
<p><!-- In this article I will show you that when using Queryable.Sum with Entity Framework and Linq to Entities to sum up a list of decimal values (or other value type) like in the following snippet you could get the exception listed below if the list is empty:[sourcecode language="csharp" wraplines="false"] try { 	using (var context = new IncomeContext()) 	{ 		var initializer = new DropCreateDatabaseAlways(); 		initializer.InitializeDatabase(context); 							 		var sum = context.Incomes.Sum(income =&gt;--> income.Amount);<br />
	}<br />
}<br />
catch (Exception exception)<br />
{<br />
	Console.WriteLine(exception.ToString());<br />
}<br />
[/sourcecode]</p>
<p>If you run this code on an empty table you will get the following exception:</p>
<pre class="brush: powershell; title: ; wrap-lines: false; notranslate">
System.InvalidOperationException: The cast to value type 'Decimal' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.
   at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
   at lambda_method(Closure , Shaper )
   at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
   at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at System.Data.Objects.ELinq.ObjectQueryProvider.b__3[TResult](IEnumerable`1 sequence)
   at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
   at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
   at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.Sum[TSource](IQueryable`1 source, Expression`1 selector)
</pre>
<p>In my example I suppose that you already used <strong>Entity Framework Code First</strong>.<br />
I explicitly invoke a DatabaseInitializer to be sure to create a freshly new database.<br />
I previously created a <strong>DbContext</strong> with a single Dbset of <strong>Incomes</strong> entities:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">
public class IncomeContext : DbContext
{
	public DbSet Incomes { get; set; }
}
</pre>
<p>I created an Income entity:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">
public class Income
{
    public long Id { get; set; }

    public decimal Amount { get; set; }
}
</pre>
<p>The Linq query we coded at the beginning of the post is translated into the following SQL query and such SQL query will return null if no t-uple is found matching the filtering criteria.</p>
<pre class="brush: sql; title: ; wrap-lines: false; notranslate">
SELECT
[GroupBy1].[A1] AS [C1]
FROM ( SELECT
	SUM([Extent1].[Amount]) AS [A1]
	FROM [dbo].[Incomes] AS [Extent1]
)  AS [GroupBy1]
</pre>
<p>If we want to avoid the exception we need to cast to decimal? the return value of the lambda expression.<br />
In that way the overload resolution will end up with the Sum overload returning a decimal?.<br />
At this point you can work with the result as you want. With a coalesce operator for example:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">
try
{
	using (var context = new PersonContext())
	{
		var initializer = new DropCreateDatabaseAlways();
		initializer.InitializeDatabase(context);

		var sum = context.Incomes
			.Sum(income =&gt;  (decimal?)income.Amount) ?? 0;
	}
}
catch (Exception exception)
{
	Console.WriteLine(exception.ToString());
}
</pre>
<p>&#8211;&gt;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ilmatte.wordpress.com/2012/12/20/queryable-sum-on-decimal-and-null-return-value-with-linq-to-entities/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">612</post-id>
		<media:content url="https://0.gravatar.com/avatar/9b6dfe5bd4ef55adc68d6b8a3127bb384d6c8eb25356dfe4fb2bb050e9145f8d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>
	</item>
		<item>
		<title>Optimize Linq To Entities queries using let clauses</title>
		<link>https://ilmatte.wordpress.com/2012/12/18/optimize-linq-to-entities-queries-using-let-clauses/</link>
					<comments>https://ilmatte.wordpress.com/2012/12/18/optimize-linq-to-entities-queries-using-let-clauses/#comments</comments>
		
		<dc:creator><![CDATA[ilmatte]]></dc:creator>
		<pubDate>Tue, 18 Dec 2012 22:46:27 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Code First]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Let Clause]]></category>
		<category><![CDATA[Optimize Linq To Entities]]></category>
		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=600</guid>

					<description><![CDATA[This post is no longer maintained. Click here for the updated version of this post &#60;!&#8211; In this article I will show you that let clauses inside Linq queries are not a simple matter of readability of the query, when it comes to using Entity Framework and the Linq to Entities provider. In some cases, [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1><span style="color:#3366ff;"><a title="linktorevisedpost" href="http://theworkingdad.it/en/2018/10/02/optimize-linq-to-entities-queries-using-let-clauses/" name="linktorevisedpost">This post is no longer maintained. Click here for the updated version of this post</a></span></h1>
<p>&lt;!&#8211;<br />
In this article I will show you that <strong>let clauses</strong> inside Linq queries are not a simple matter of readability of the query, when it comes to using Entity Framework and the Linq to Entities provider.<br />
In some cases, in fact, they can provide a little bit of optimization of the SQL query generated.<br />
In my example I suppose that you already used <strong>Entity Framework Code First</strong>.<br />
I create a <strong>DbContext</strong> with a single Dbset of <strong>Person</strong> entities:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">
public class PersonContext : DbContext
{
	public DbSet Persons { get; set; }
}
</pre>
<p>I create a Person entity and an Address entity which is a child entity of Person:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">
public class Person
{
	public long PersonId { get; set; }

	public string Name { get; set; }

	public string Surname { get; set; }

	public Address Address { get; set; }
}

public class Address
{
	public long AddressId { get; set; }

	public string Town { get; set; }

	public string Street { get; set; }
}
</pre>
<p>The <strong>Address</strong> type is an entity and not a complex type because it has an <strong>AddressId</strong> property defined.<br />
With two entities in place Entity Framework Code First will generate two tables via the DatabaseInitializer configured.<br />
What I want to show is that if I want to select some Persons filtering on their Town and Street using a Linq query, I could and up sending to the Database a couple of joins between Person and Address instead of one, unless I use <strong>let clauses</strong>.</p>
<p>Let&#8217;s create a test or a Console application with the following code:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">
try
{
   using (var context = new PersonContext())
   {
	 var initializer = new DropCreateDatabaseAlways();
	 initializer.InitializeDatabase(context);

	 context.Persons.Add(new Person { Surname = "Smith" });
	 context.SaveChanges();

	 var result = from person in context.Persons
	               where person.Address.Street == "A" &amp;&amp;
		               person.Address.Town == "B"
	  	           select person;
	 var list = result.ToList();

	 result = from person in context.Persons
	 	      let address = person.Address
		      where address.Street == "A" &amp;&amp;
		            address.Town == "B"
		      select person;
	 list = result.ToList();
   }
}
catch (Exception exception)
{
   Console.WriteLine(exception.ToString());
}
</pre>
<p>In the preceding code snippet we explicitly invoke a DatabaseInitializer to be sure to create a freshly new database. We insert a Person entity (but we could have omitted this part for the sake of the example). Then we execute the same query once with a let clause and once without.</p>
<p>If you run Sql Server Profiler to see the queries sent to the Database and run your test or application you will see the following two SQL queries.<br />
The first one is the result of the Linq query without the let clause:</p>
<pre class="brush: sql; title: ; wrap-lines: false; notranslate">
SELECT
1 AS [C1],
[Filter1].[PersonId] AS [PersonId],
[Filter1].[Name] AS [Name],
[Filter1].[Surname] AS [Surname],
[Filter1].[Address_AddressId] AS [Address_AddressId]
FROM   (SELECT [Extent1].[PersonId] AS [PersonId], [Extent1].[Name] AS [Name], [Extent1].[Surname] AS [Surname], [Extent1].[Address_AddressId] AS [Address_AddressId]
	FROM  [dbo].[People] AS [Extent1]
	INNER JOIN [dbo].[Addresses] AS [Extent2] ON [Extent1].[Address_AddressId] = [Extent2].[AddressId]
	WHERE N'A' = [Extent2].[Street] ) AS [Filter1]
INNER JOIN [dbo].[Addresses] AS [Extent3] ON [Filter1].[Address_AddressId] = [Extent3].[AddressId]
WHERE N'B' = [Extent3].[Town]
</pre>
<p>The second one gives the result we would have coded if we wrote the SQL directly.</p>
<pre class="brush: sql; title: ; wrap-lines: false; notranslate">
SELECT
1 AS [C1],
[Extent1].[PersonId] AS [PersonId],
[Extent1].[Name] AS [Name],
[Extent1].[Surname] AS [Surname],
[Extent1].[Address_AddressId] AS [Address_AddressId]
FROM  [dbo].[People] AS [Extent1]
INNER JOIN [dbo].[Addresses] AS [Extent2] ON [Extent1].[Address_AddressId] = [Extent2].[AddressId]
WHERE (N'A' = [Extent2].[Street]) AND (N'B' = [Extent2].[Town])
</pre>
<p>We can conclude that everytime we use more than once a navigation property inside of a Linq query against the Linq To Entities provider we&#8217;d better store the navigation property in a let clause and use the so defined variable instead.</p>
<p>&#8211;&gt;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ilmatte.wordpress.com/2012/12/18/optimize-linq-to-entities-queries-using-let-clauses/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">600</post-id>
		<media:content url="https://0.gravatar.com/avatar/9b6dfe5bd4ef55adc68d6b8a3127bb384d6c8eb25356dfe4fb2bb050e9145f8d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>
	</item>
		<item>
		<title>Entity Framework 5 Code First: Enabling Migrations in a Real Project</title>
		<link>https://ilmatte.wordpress.com/2012/12/05/entity-framework-5-code-first-enabling-migrations-in-a-real-project/</link>
					<comments>https://ilmatte.wordpress.com/2012/12/05/entity-framework-5-code-first-enabling-migrations-in-a-real-project/#comments</comments>
		
		<dc:creator><![CDATA[ilmatte]]></dc:creator>
		<pubDate>Tue, 04 Dec 2012 23:08:46 +0000</pubDate>
				<category><![CDATA[Code First]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Migrations]]></category>
		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=564</guid>

					<description><![CDATA[This post is no longer maintained. Click here for the updated version of this post &#60;!&#8211; In this article I will try to explain how to enable and use Entity Framework&#8217;s Code First Migrations in a real project (i.e.: a solution with many projects, a database server, etc). The Target Entity Framework is version 5. [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1><span style="color:#3366ff;"><a title="linktorevisedpost" href="http://theworkingdad.it/en/2018/10/01/entity-framework-5-code-first-enabling-migrations-in-a-real-project/" name="linktorevisedpost">This post is no longer maintained. Click here for the updated version of this post</a></span></h1>
<p>&lt;!&#8211;</p>
<div>
<a href="http://autocompletedotnet.codeplex.com/"><br />
<img src="https://ilmatte.wordpress.com/wp-content/uploads/2011/07/autocompletebanner.png?w=510" alt="Autocomplete Banner" /></a></div>
<p>In this article I will try to explain how to enable and use Entity Framework&#8217;s Code First Migrations in a real project (i.e.: a solution with many projects, a database server, etc).</p>
<p>The Target Entity Framework is version 5.</p>
<p>Open Visual Studio 2010 and create a new console application.</p>
<p>I named the example solution: <strong>EF5CodeFirst</strong></p>
<p>and the project (guess how&#8230;): <strong>ConsoleApplication</strong>.</p>
<p>Add a class library project and name it, say: <strong>Model</strong>.</p>
<p>In my example I replaced the template generated: <strong>Class1.cs</strong> with a <strong>Person.cs</strong> file containing the following code:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">
public class Person
{
	public long PersonId { get; set; }
	public string Name { get; set; }
	public string SurName { get; set; }
}
</pre>
<p>Add another class library project, name it: <strong>Persistence</strong> and remove the file: <strong>Class1.cs</strong>.</p>
<p>Now I want to add Entity Framework to my project</p>
<p>It&#8217;s time to close Visual Studio and install the latest version of <strong>NuGet</strong>, if you haven&#8217;t got it yet.</p>
<p>You can find it here (<a href="http://nuget.codeplex.com/" target="_blank">http://nuget.codeplex.com</a>).</p>
<p>Important Notice:</p>
<p>To successfully install the Entity Framework package you need Powershell 2.0 installed, so be sure to upgrade your machine if you work on Windows Xp for example.</p>
<p>Once installed <strong>NuGet</strong>, open your solution, right click the <strong>Persistence</strong> project and choose:</p>
<p><strong>Manage NuGet Packages&#8230;</strong></p>
<p>In the new window choose: <strong>Online</strong> in the left menu.</p>
<p>Write: Entity Framework, in the search field on the top right and hit Enter.</p>
<p>You will get a list of options in the center panel. The first one will be: Entity Framework.</p>
<p>Click the corresponding: <strong>Install</strong> button.</p>
<p>The package will be downloaded, you will be asked to accept the license agreement and eventually the Entity Framework will be installed in your solution folder tree and the <strong>Persistence</strong> project will get a default configuration for Entity Framework.</p>
<p>Let&#8217;s go a little bit in the details of what this configuration is:</p>
<p>If you expand your project in solution explorer you will find that a reference has been added to the EntityFramework assembly. The referenced assembly has been installed in a default location under the solution folder.</p>
<p>NuGet creates a folder named: packages at the same level as the solution file.</p>
<p>Inside that folder you will find a configuration file (used by Nuget) and the EntityFramework.5.0.0 folder.</p>
<p>From now on every new package you will install will have its own folder inside the packages path.</p>
<p>Inside its own folder every package can be organized with its own structure.</p>
<p>You will find the Entity Framework assembly under the path:</p>
<p>EntityFramework.5.0.0\lib\net40 (or net45).</p>
<p>Nuget added a reference to your project choosing the right assembly based on the target framework of your solution.</p>
<p>Going back to solution explorer and to our <strong>Persistence</strong> project you will find a packages.config file needed by NuGet to track the packages installed and to be able to uninstall them if required.</p>
<p>Strange to see you will find also an <strong>App.config</strong> file. Such file has been added by NuGet to configure the project to be used with Sql Express, if installed, or with LocalDB.</p>
<p>&#8220;If SQL Express is installed (included in Visual Studio 2010) then the database is created on your local SQL Express instance (.\SQLEXPRESS). If SQL Express is not installed then Code First will try and use LocalDb ((localdb)\v11.0) &#8211; LocalDb is included with Visual Studio 2012.&#8221;</p>
<p>In our example the App.config file should be moved to the: <strong>ConsoleApplication</strong> project.</p>
<p>Let&#8217;s have a look at its contents:</p>
<p>A configuration has been added to the file, specifying the &#8220;defaultConnectionFactory&#8221; to be used (e.g.: LocalDbConnectionFactory).</p>
<p>In a real environment you will probably have a development database server to be used during the development of your solution, maybe a staging server and eventually a production server.</p>
<p>If you want to configure your project to work with a SqlServer database you need to specify as defaultConnectionFactory the SqlConnectionFactory.</p>
<p>Important thing to know is that the SqlConnectionFactory is the default factory used, if you don&#8217;t specify anything in your App.config.</p>
<p>So we can definitely delete the App.config file added by NuGet.</p>
<p>Now you need to specify the connection string that will be used by your start-up project: <strong>ConsoleApplication</strong>, so you need to add an App.config in the console project and add the connection strings configuration section in it:</p>
<pre class="brush: xml; title: ; wrap-lines: false; notranslate">

</pre>
<p>Be sure to specify the credentials of a user with Database creation permissions.</p>
<p>Now add the code first context to the <strong>Persistence</strong> project:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">
public class PersonContext : DbContext
{
	public PersonContext() : base("TestConnectionString") {}

	public DbSet Persons { get; set; }
}
</pre>
<p>adding references and importing namespaces as required.</p>
<p>The constructor explicitely invoking the base one allows us to specify the connection string to be used, bypassing the convention that expects a connection string with the same name as our DbContext class (i.e.: PersonContext).</p>
<p>Now we need to create an instance of our context and enumerate a resultset to let the default <strong>DatabaseInitializer</strong> be invoked and therefore the database be created.</p>
<p>Let&#8217;s add the following code to the <strong>Program.cs</strong> file in the <strong>ConsoleApplication</strong> project, adding references to the required projects and to the Entity Framework assembly.</p>
<p>If you want to be able to manage Entity Framework entirely via NuGet you need to add the reference again using NuGet, otherwise just add a reference.</p>
<p>If you choose to use NuGet you will have to clean the <strong>ConsoleApplication</strong>&#8216;s App.config leaving only the ConnectionStrings section we previously added.</p>
<p>Then run the application:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">
static void Main(string[] args)
{
	try
	{
		using (var context = new PersonContext())
		{
			context.Persons.Add(new Person { Surname = "Smith" });
			context.SaveChanges();

			foreach (var person in context.Persons)
			{
				Console.WriteLine(person.Surname);
			}
		}
	}
	catch (Exception exception)
	{
		Console.WriteLine(exception.ToString());
	}
}
</pre>
<p>In your database server you will find a new database named: <strong>EF5Test</strong> with a table named: People.</p>
<p>In the System Tables, the Entity Framework&#8217;s database initializer created a table named: <strong>__MigrationHistory</strong> that Entity Framework will use to check database version and apply schema migrations.</p>
<p>The table contains the first &#8216;migration&#8217; record which represents the current version of the database.</p>
<p>If we modify the Person type adding a new property, say: <strong>Address</strong>:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">
public class Person
{
	public long PersonId { get; set; }

	public string Name { get; set; }

	public string Surname { get; set; }

	public string Address { get; set; }
}
</pre>
<p>and try to run the application again we will get the following error:</p>
<p>&#8220;System.InvalidOperationException: The model backing the &#8216;PersonContext&#8217; context</p>
<p>has changed since the database was created. Consider using Code First Migrations</p>
<p>to update the database (<a title="http://go.microsoft.com/fwlink/?LinkId=238269" href="http://go.microsoft.com/fwlink/?LinkId=238269">http://go.microsoft.com/fwlink/?LinkId=238269</a>).&#8221;</p>
<p>This depends on the default Database Initializer used by EntityFramework: CreateDatabaseIfNotExists.</p>
<p>If you&#8217;re still developing your application you don&#8217;t need to create a new Migration for any change in the Model, you just need to configure the Database Initializer you wish to use.</p>
<p>In our case we want to recreate the database every time the model changes so we will add the following line of code just before the using statement in Program.cs in our ConsoleApplication project:</p>
<pre class="brush: csharp; gutter: false; title: ; wrap-lines: false; notranslate">
Database.SetInitializer(new DropCreateDatabaseIfModelChanges());
</pre>
<p>I suggest to always have a Fixtures project so that you can leave your application throw an exception if the Model changes with respect to the database schema while your Fixture project would contain a Fixture to regenerate the Database every time you modify the model.</p>
<p>I personally suggest Nunit but for our example we will go with the modification to the Console Application.</p>
<p>Run your application again (or run your test if you&#8217;ve got one) and you will see that the database has been regenerated with the new Address column in the People table.</p>
<p>Let&#8217;s now comment out for a while the Address property from the Person class and rerun the application to regenerate the database.</p>
<p>We can see the table: __MigrationHistory in the system tables, containing a record representing the first migration (the current database version).</p>
<p>We need to tell EntityFramework to classify such information as Migration number 1 and save this information somehow in the Visual Studio solution for later use.</p>
<p>1)<br />
First of all we have to run the <strong>Enable-Migrations</strong> command in Package Manager Console. The exact syntax is:</p>
<pre class="brush: plain; title: ; wrap-lines: false; notranslate">
Enable-Migrations -ProjectName "Persistence" -StartUpProjectName "ConsoleApplication"
</pre>
<p>This command will create in the Persistence project a Configuration class representing how Migrations will behave for my DbContext.</p>
<p>Being that we already generated the Database by running the application, the execution of the Enable-Migrations command also generates an initial migration, named: [timestamp]_InitialCreate.cs with the code below, scaffolded from the existing database.<br />
If we didn&#8217;t create the database yet, this initial migration would have been included in the first generated Migration.</p>
<p>The command parameters have the following meaning:<br />
<strong>-ProjectName</strong>: specifies the target project to create the migration in.<br />
<strong>-StartupProjectName</strong>: specifies the target project to look for a configuration file containing a connection string.<br />
If not specified the Visual Studio solution startup project is used.<br />
The project must contain the actual configuration file and not a link to it.</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">
public partial class InitialCreate : DbMigration
{
	public override void Up()
	{
		CreateTable(
			"dbo.People",
			c =&gt; new
				{
					PersonId = c.Long(nullable: false, identity: true),
					Name = c.String(),
					Surname = c.String(),
				})
			.PrimaryKey(t =&gt; t.PersonId);

	}

	public override void Down()
	{
		DropTable("dbo.People");
	}
}
</pre>
<p>2)<br />
From now on, every time we want to add a new Migration we need to run the: <strong>Add-Migration</strong> command in the Package Manager Console:</p>
<pre class="brush: plain; title: ; wrap-lines: false; notranslate">
Add-Migration YourMigrationName -ProjectName "Persistence" -StartUpProjectName "ConsoleApplication"
</pre>
<p>When invoking Add-Migration just specify a name for your Migration (e.g.: AddAddress) and the two parameters specifying the projects as in the Enable-Migrations command.<br />
The code for the new Migration will be scaffolded, by comparing our model with the last Migration created, and the generated code will be added to the Persistence project.</p>
<p>Let&#8217;s now uncomment the Address property and suppose we want to release this new version of the application as a new Migration.<br />
Run the following command:</p>
<pre class="brush: plain; title: ; wrap-lines: false; notranslate">
Add-Migration AddAddress -ProjectName "Persistence" -StartUpProjectName "ConsoleApplication"
</pre>
<p>In the Migrations folder, in the Persistence project, a new migration will appear, named [timestamp]_AddAddress.cs and with the following content:</p>
<pre class="brush: csharp; title: ; wrap-lines: false; notranslate">
public partial class AddAddress : DbMigration
{
	public override void Up()
	{
		AddColumn("dbo.People", "Address", c =&gt; c.String());
	}

	public override void Down()
	{
		DropColumn("dbo.People", "Address");
	}
}
</pre>
<p>If  you refresh your Database in Sql Server Management Studio you will see that the &#8216;People&#8217; table still does not have an &#8216;Address&#8217; column.</p>
<p>3)<br />
Every time we want to apply a new Migration we need to run the: <strong>Update-Database</strong> command in the Package Manager Console:</p>
<pre class="brush: plain; title: ; wrap-lines: false; notranslate">
Update-Database -ProjectName "Persistence" -StartUpProjectName "ConsoleApplication"
</pre>
<p>When invoking Update-Database just specify the two parameters specifying the projects as in the Enable-Migrations command.<br />
All the pending Migrations, after the last applied, will be applied to the Database found in the connection string specified in the StartUpProject specified.<br />
We can specify the name of the target Migration we want to update the Database by adding the following parameter:</p>
<p><strong>–TargetMigration</strong>: AddAddress.</p>
<p>In our example after running the Update-Database command and refreshing the Database we will find a new &#8216;Address&#8217; column in the &#8216;People&#8217; table.</p>
<p>If we then want to revert the Migration we can do it with the following command:</p>
<pre class="brush: plain; title: ; wrap-lines: false; notranslate">
Update-Database -ProjectName "Persistence" -StartUpProjectName "ConsoleApplication" –TargetMigration: InitialCreate
</pre>
<p>4)<br />
If we don&#8217;t want to apply our Migration directly but release a script to our DBA, which is a very reasonable requirement for a production environment, we can modify the Update-Database to generate a script and not apply any changes to the Database.</p>
<p>To achieve this just add the following parameter:</p>
<p><strong>-Script</strong></p>
<p>that will cause the command to generate an sql file that will be opened in Visual Studio.<br />
The generated file will contain the migration scripts starting from the last applied migration.</p>
<p>If we want to start from a specified Migration we can add the following parameter:</p>
<p><strong>-SourceMigration</strong>:MigrationName.</p>
<p>If we want to start with an empty Database we can associate a special keyword as value to that parameter:</p>
<p><strong>-SourceMigration:$InitialDatabase</strong></p>
<p>Let&#8217;s generate a script to release in a new production environment all the migrations starting from an empty Database. We can do it with the following command:</p>
<pre class="brush: plain; title: ; wrap-lines: false; notranslate">
Update-Database -ProjectName "Persistence" -StartUpProjectName "ConsoleApplication" -Script -SourceMigration:$InitialDatabase
</pre>
<p>obtaining:</p>
<pre class="brush: sql; title: ; wrap-lines: false; notranslate">
CREATE TABLE [dbo].[People] (
    [PersonId] [bigint] NOT NULL IDENTITY,
    [Name] [nvarchar](max),
    [Surname] [nvarchar](max),
    CONSTRAINT [PK_dbo.People] PRIMARY KEY ([PersonId])
)
CREATE TABLE [dbo].[__MigrationHistory] (
    [MigrationId] [nvarchar](255) NOT NULL,
    [Model] [varbinary](max) NOT NULL,
    [ProductVersion] [nvarchar](32) NOT NULL,
    CONSTRAINT [PK_dbo.__MigrationHistory] PRIMARY KEY ([MigrationId])
)
BEGIN TRY
    EXEC sp_MS_marksystemobject 'dbo.__MigrationHistory'
END TRY
BEGIN CATCH
END CATCH
INSERT INTO [__MigrationHistory] ([MigrationId], [Model], [ProductVersion]) VALUES ('201211152147401_InitialCreate', [hash], '5.0.0.net40')
ALTER TABLE [dbo].[People] ADD [Address] [nvarchar](max)
INSERT INTO [__MigrationHistory] ([MigrationId], [Model], [ProductVersion]) VALUES ('201212032151179_AddAddress', [hash], '5.0.0.net40')
</pre>
<p>&#8211;&gt;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ilmatte.wordpress.com/2012/12/05/entity-framework-5-code-first-enabling-migrations-in-a-real-project/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">564</post-id>
		<media:content url="https://0.gravatar.com/avatar/9b6dfe5bd4ef55adc68d6b8a3127bb384d6c8eb25356dfe4fb2bb050e9145f8d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>

		<media:content url="https://ilmatte.wordpress.com/wp-content/uploads/2011/07/autocompletebanner.png" medium="image">
			<media:title type="html">Autocomplete Banner</media:title>
		</media:content>
	</item>
		<item>
		<title>AutoComplete.Net</title>
		<link>https://ilmatte.wordpress.com/2011/06/18/autocomplete-net/</link>
					<comments>https://ilmatte.wordpress.com/2011/06/18/autocomplete-net/#respond</comments>
		
		<dc:creator><![CDATA[ilmatte]]></dc:creator>
		<pubDate>Sat, 18 Jun 2011 22:44:35 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[Asp.Net MVC]]></category>
		<category><![CDATA[AutoComplete]]></category>
		<category><![CDATA[JQuery UI]]></category>
		<guid isPermaLink="false">http://ilmatte.wordpress.com/?p=476</guid>

					<description><![CDATA[This post is no longer maintained. Click here for the updated version of this post &#160;]]></description>
										<content:encoded><![CDATA[<h1><span style="color:#3366ff;"><a title="linktorevisedpost" href="http://theworkingdad.it/en/2018/09/30/autocomplete-net/" name="linktorevisedpost">This post is no longer maintained. Click here for the updated version of this post</a></span></h1>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ilmatte.wordpress.com/2011/06/18/autocomplete-net/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">476</post-id>
		<media:content url="https://0.gravatar.com/avatar/9b6dfe5bd4ef55adc68d6b8a3127bb384d6c8eb25356dfe4fb2bb050e9145f8d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ilmatte</media:title>
		</media:content>
	</item>
	</channel>
</rss>
