<?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/"
	>

<channel>
	<title>MsHelp &#187; .NET 4.0</title>
	<atom:link href="http://mshelp.be/category/net-40/feed" rel="self" type="application/rss+xml" />
	<link>http://mshelp.be</link>
	<description>Ins and Outs of Microsoft Dynamics CRM</description>
	<lastBuildDate>Fri, 06 Apr 2012 11:09:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Entity Framework 4.0 &#8211; Part4: How to use your own POCO&#8217;s</title>
		<link>http://mshelp.be/entity-framework-4-0-part4-how-to-use-your-own-pocos-333.htm</link>
		<comments>http://mshelp.be/entity-framework-4-0-part4-how-to-use-your-own-pocos-333.htm#comments</comments>
		<pubDate>Tue, 23 Mar 2010 22:54:29 +0000</pubDate>
		<dc:creator>Sven</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Entity Framework]]></category>

		<guid isPermaLink="false">http://mshelp.be/entity-framework-4-0-part4-how-to-use-your-own-pocos-333.htm</guid>
		<description><![CDATA[These tutorials are built using Visual Studio 2010 RC and .NET 4.0. RC. This means that Entity Framework 4.0 is used. At the moment of writing this, VS2010 and .NET 4.0 are not yet released as RTM so information provided in this post could change in the future. In the previous articles I mainly talked [...]]]></description>
			<content:encoded><![CDATA[<p><em>These tutorials are built using Visual Studio 2010 RC and .NET 4.0. RC. This means that Entity Framework 4.0 is used. At the moment of writing this, VS2010 and .NET 4.0 are not yet released as RTM so information provided in this post could change in the future.</em></p>
<p>In the previous articles I mainly talked about things you could already do with eelier version of Entity Framework. EF4.0 has some better tooling, we saw this already with the <a href="http://mshelp.be/entity-framework-4-0-part3-complex-types-330.htm">complex types</a>. With the new version of Entity Framework there is also out of the box support for POCO (<a href="http://en.wikipedia.org/wiki/Plain_Old_CLR_Object">Plain Old CLR Objects</a>). This I personally like very much because Iâ€™m not such a big fan of generated classes. Previously you didnâ€™t have much choice. You had to work with the objectâ€™s that EF generated for you. Did you have some specific logic in your property getters or setters? Then you had to find another solution. Remapping your objects to something else was one of them. You could not rely on these generated classes to contain custom business logic. If you rebuilt the edmx, your custom logic would be removed and the classes would be regenerated. There were however some clever tricks to get POCO support working before EF4.0. For instance have a look at: <span style="text-decoration: underline;"><a href="http://code.msdn.microsoft.com/EFPocoAdapter">Persistence Ignorance (POCO) Adapter for Entity Framework</a>.</span></p>
<p>In EF4.0 we have POCO support, so we can use our own business objects, domain objects. so letâ€™s jump into the code and see how we work with that. Iâ€™ll use the same database as I used before.</p>
<p>- Create a new console application</p>
<p>- Add a new file to the project, choose ADO.NET Entity Data Model</p>
<p><a href="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_thumb.png" border="0" alt="image" width="644" height="446" /></a></p>
<p>- Here we see the same screen as we did before. Again weâ€™ll create a model based on the database. This is not obliged. You could create the model yourself, but for this I would just let EF generate the classes for you. You will save yourself a lot of time.</p>
<p><a href="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_thumb_3.png" border="0" alt="image" width="545" height="484" /></a></p>
<p>- Now we should select our data source, Iâ€™ll choose the same database that I used before</p>
<p><a href="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_thumb_4.png" border="0" alt="image" width="546" height="484" /></a></p>
<p>- Itâ€™s time to select the tables we want to work with. Iâ€™m just going to use the Article for this.</p>
<p><a href="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_5.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_thumb_5.png" border="0" alt="image" width="540" height="484" /></a></p>
<p>- If everything is fine, you should end up with the following diagram</p>
<p><a href="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_thumb_6.png" border="0" alt="image" width="560" height="484" /></a></p>
<p>-So letâ€™s summarize what happened:</p>
<blockquote><p>- EF retrieved the information on the database<br />
- Retrieved specific information on the table where you want to create entities for<br />
- Based on these entities, EF created the CSDL, SSDL and MSL<br />
- EF created the entities for you to access your data in the underlying table<br />
- For these entities, EF generated some classes</p></blockquote>
<p><a href="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_7.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_thumb_7.png" border="0" alt="image" width="644" height="437" /></a></p>
<p>- These generated classes are the objects that we want to replace with our own objects</p>
<p>- Letâ€™s first stop the auto generation process. Select your .edmx file in the solution explorer and press F4 to open the properties window. There you should see the property â€œCustom Toolâ€ with the value: EntityModelCodeGenerator. Go ahead and delete that value. Just make the field empty. If you rebuild now, youâ€™ll see immediately that the generated code behind file will go away.</p>
<p><a href="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_8.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_thumb_8.png" border="0" alt="image" width="361" height="350" /></a></p>
<p>- OK letâ€™s start by creating our POCO. One thing to remember is that this has to be EXACTLY the same as your entity. Do it wrong and you WILL get exceptionsâ€¦Iâ€™ll go over this later</p>
<p>- First letâ€™s create the Article class</p>
<div id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c2514ed3-1b11-42e2-a168-30965c966442" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #000000;">    </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> Article
    {
       </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">int</span><span style="color: #000000;"> Id { </span><span style="color: #0000FF;">get</span><span style="color: #000000;">; </span><span style="color: #0000FF;">set</span><span style="color: #000000;">; }
       </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">string</span><span style="color: #000000;"> Name { </span><span style="color: #0000FF;">get</span><span style="color: #000000;">; </span><span style="color: #0000FF;">set</span><span style="color: #000000;">; }
       </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">string</span><span style="color: #000000;"> Description { </span><span style="color: #0000FF;">get</span><span style="color: #000000;">; </span><span style="color: #0000FF;">set</span><span style="color: #000000;">; }
       </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> Double Price { </span><span style="color: #0000FF;">get</span><span style="color: #000000;">; </span><span style="color: #0000FF;">set</span><span style="color: #000000;">; }
       </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">int</span><span style="color: #000000;"> Stock { </span><span style="color: #0000FF;">get</span><span style="color: #000000;">; </span><span style="color: #0000FF;">set</span><span style="color: #000000;">; }
    }</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>- As you can see this matches to my entity shown in the previous image</p>
<p>- Now we need a way of connecting to the model. The bridge between your POCO and the edmx file containing the mapping schema etc is the <a href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx">ObjectContext class</a>. This class uses the connection string in the App.Config file to connect to the edmx file and the underlying table. The connection string is one of the parameters we need to pass to the base constructor of the ObjectContext. In this ObjectContext implementation weâ€™ll also define the entities. This is called an <a href="http://msdn.microsoft.com/en-us/library/dd412719%28VS.100%29.aspx">ObjectSet</a>, thatâ€™s what we are adding to the ObjectContext. Letâ€™s have a look at this now:</p>
<div id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c2d45218-eca0-4d44-b262-43fe7d585564" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> ArticleModel:ObjectContext
    {
        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> IObjectSet</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">Article</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> Articles { </span><span style="color: #0000FF;">get</span><span style="color: #000000;">; </span><span style="color: #0000FF;">set</span><span style="color: #000000;">; }
        </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> ArticleModel()
            : </span><span style="color: #0000FF;">base</span><span style="color: #000000;">(</span><span style="color: #800000;">"</span><span style="color: #800000;">name=DemoDBEntities</span><span style="color: #800000;">"</span><span style="color: #000000;">,</span><span style="color: #800000;">"</span><span style="color: #800000;">DemoDBEntities</span><span style="color: #800000;">"</span><span style="color: #000000;">)
        {
            </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (Articles </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">)
                Articles </span><span style="color: #000000;">=</span><span style="color: #000000;"> CreateObjectSet</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">Article</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">();
        }
    }</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>- I donâ€™t think much explanation is needed anymore. The first parameter that I pass to the base constructor of the ObjectContext class is the connection string, the second one is the name of the container. There are some different ways that you can do this..the Object Browser tells you how:</p>
<p><a href="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_9.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_thumb_9.png" border="0" alt="image" width="644" height="434" /></a></p>
<p>- OK weâ€™re almost done! Now letâ€™s test run what we just created</p>
<div id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:afe5df71-60cb-4fab-bdc7-fde4ab927e23" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<pre style="background-color:#FFFFFF;white-space:-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word;overflow: auto;"><span style="color: #000000;">    </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> Program
    {
    </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> Main(</span><span style="color: #0000FF;">string</span><span style="color: #000000;">[] args)
    {
        var am </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> ArticleModel();

        </span><span style="color: #0000FF;">foreach</span><span style="color: #000000;"> (var art </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> am.Articles)
        {
            Console.WriteLine(art.Name);
        }
        Console.ReadLine();
    }</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p><a href="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_10.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.mshelp.be/img/EntityFramewo.0Part4HowtouseyourownPOCOs_14EF6/image_thumb_10.png" border="0" alt="image" width="644" height="326" /></a></p>
<p><strong>Exceptions</strong></p>
<p>Now something short on exceptions because exception can occur while working with your own POCOâ€™s.</p>
<p>- Make sure your object properties are the same as the properties in your EF entity. If you donâ€™t have the same properties, then youâ€™ll receive an InvalidOperationException saying something like: <strong>Mapping and metadata information could not be found for EntityType &#8216;EFPOCO1.Article&#8217;. </strong>I donâ€™t like these kind of errors because they do not show which column is wrong. You have match every property and see which one is different.</p>
<p>- Make sure your App.Config can be read. If the ObjectContext canâ€™t locate the App.Config or the name of the connection string is incorrect then youâ€™ll receive an ArgumentException saying something like: <strong>The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid. </strong></p>
<p>OK as you can see it isnâ€™t that hard to use your own POCOâ€™s. Iâ€™m not saying EF generated classes are bad, itâ€™s just that if you have some specific logic that you want to have in your objects, then youâ€™re kind of stuck and need to be creative.</p>
<p>Anyway, hope this was informative.</p>
<p><a rev="vote-for" href="http://dotnetshoutout.com/MsHelp-Entity-Framework-40-Part4-How-to-use-your-own-POCOs"><img style="border:0px" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fmshelp.be%2Fentity-framework-4-0-part4-how-to-use-your-own-pocos-333.htm" alt="Shout it" /></a><br />
<a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fmshelp.be%2fentity-framework-4-0-part4-how-to-use-your-own-pocos-333.htm"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmshelp.be%2fentity-framework-4-0-part4-how-to-use-your-own-pocos-333.htm" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://mshelp.be/entity-framework-4-0-part4-how-to-use-your-own-pocos-333.htm/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Entity Framework 4.0 &#8211; Part3: Complex types</title>
		<link>http://mshelp.be/entity-framework-4-0-part3-complex-types-330.htm</link>
		<comments>http://mshelp.be/entity-framework-4-0-part3-complex-types-330.htm#comments</comments>
		<pubDate>Mon, 22 Mar 2010 20:04:14 +0000</pubDate>
		<dc:creator>Sven</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Entity Framework]]></category>

		<guid isPermaLink="false">http://mshelp.be/entity-framework-4-0-part3-complex-types-330.htm</guid>
		<description><![CDATA[These tutorials are built using Visual Studio 2010 RC and .NET 4.0. RC. This means that Entity Framework 4.0 is used. At the moment of writing this, VS2010 and .NET 4.0 are not yet released as RTM so information provided in this post could change in the future. A complex type is a set of [...]]]></description>
			<content:encoded><![CDATA[<p>These tutorials are built using Visual Studio 2010 RC and .NET 4.0. RC. This means that Entity Framework 4.0 is used. At the moment of writing this, VS2010 and .NET 4.0 are not yet released as RTM so information provided in this post could change in the future.</p>
<p>A complex type is a set of properties that you group together. Sometimes your code becomes more clear when you group together properties. In this part Iâ€™ll show you how you can create complex types from the designer. Before EF4.0, you could also create these complex types. The only downside was that you had to do it manually in the conceptual model.</p>
<p>In the <a href="http://mshelp.be/entity-framework-4-0-part2-updating-the-entity-model-from-a-database-328.htm">previous post</a> I created a new entity called Person. As you can see below, this Person entity contains all the classic properties.</p>
<p><a href="http://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image.png"><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://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image_thumb.png" width="160" height="243" /></a> </p>
<p>Now I want to group Street, PostalCode and City together in a new complex type, Address. Then I have all the address related properties together. Procedure is as follows:</p>
<ul>
<li>Hold CTRL and select the properties in the model that you want to group together </li>
<li>Click on the right mouse button and in the context menu select â€œRefactor into New Complex Typeâ€ </li>
</ul>
<p><a href="http://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image_3.png"><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://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image_thumb_3.png" width="474" height="422" /></a> </p>
<p>Now youâ€™ll see that the model browser comes up and adds a new Complex Type. Now letâ€™s give a more meaningful name. If you open the complex type, youâ€™ll see the properties that we previously selected.</p>
<p><a href="http://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image_4.png"><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://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image_thumb_4.png" width="303" height="259" /></a> <a href="http://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image_5.png"><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://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image_thumb_5.png" width="303" height="295" /></a> </p>
</p>
</p>
<p>If you look at your model, youâ€™ll see that a ComplexProperty has been added to the list. If you look at the properties, you will see that the type of this ComplexProperty is actual the Address complex type that we just created.</p>
<p>Iâ€™ll rename this to Address as well, it will make it more clear.</p>
<p><a href="http://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image_6.png"><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://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image_thumb_6.png" width="158" height="203" /></a> <a href="http://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image_7.png"><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://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image_thumb_7.png" width="317" height="202" /></a> </p>
<p>Ok now letâ€™s see how we can use this complex type:</p>
<p><a href="http://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image_8.png"><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://www.mshelp.be/img/EntityFramework4.0Part3Complextypes_E8D9/image_thumb_8.png" width="347" height="316" /></a></p>
<p>  <a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fmshelp.be%2fentity-framework-4-0-part3-complex-types-330.htm-resharper-5-0-275.htm"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmshelp.be%2fentity-framework-4-0-part3-complex-types-330.htm-resharper-5-0-275.htm" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://mshelp.be/entity-framework-4-0-part3-complex-types-330.htm/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Entity Framework 4.0 &#8211; Part2: Updating the Entity model from a database</title>
		<link>http://mshelp.be/entity-framework-4-0-part2-updating-the-entity-model-from-a-database-328.htm</link>
		<comments>http://mshelp.be/entity-framework-4-0-part2-updating-the-entity-model-from-a-database-328.htm#comments</comments>
		<pubDate>Sat, 20 Mar 2010 14:57:51 +0000</pubDate>
		<dc:creator>Sven</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Entity Framework]]></category>

		<guid isPermaLink="false">http://mshelp.be/entity-framework-4-0-part2-updating-the-entity-model-from-a-database-328.htm</guid>
		<description><![CDATA[These tutorials are built using Visual Studio 2010 RC and .NET 4.0. RC. This means that Entity Framework 4.0 is used. At the moment of writing this, VS2010 and .NET 4.0 are not yet released as RTM so information provided in this post could change in the future. In Part1 we have created our model [...]]]></description>
			<content:encoded><![CDATA[<p>These tutorials are built using Visual Studio 2010 RC and .NET 4.0. RC. This means that Entity Framework 4.0 is used. At the moment of writing this, VS2010 and .NET 4.0 are not yet released as RTM so information provided in this post could change in the future.</p>
<p>In <a href="http://mshelp.be/entity-framework-4-0-part1-how-to-create-a-model-from-a-database-325.htm">Part1</a> we have created our model from a database. Now you have made some changes to the underlying database and want to update the model.&#160; For example: you created a new table in the database and also want to create an entity for this. No worries, you donâ€™t need to delete the model and regenerate it.</p>
<p>Right click in the diagram and choose â€œUpdate Model from Databaseâ€¦â€</p>
<p><a href="http://www.mshelp.be/img/Ent.0Part2UpdatingtheEntitymodelfromadat_DDB5/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.mshelp.be/img/Ent.0Part2UpdatingtheEntitymodelfromadat_DDB5/image_thumb.png" width="329" height="317" /></a> </p>
<p>This will open the Update Wizard. This window will show all the tables in the underlying database that are not yet represented by entities in your model. Here you can select the tables where you want to generate entities for.</p>
<p><a href="http://www.mshelp.be/img/Ent.0Part2UpdatingtheEntitymodelfromadat_DDB5/image_3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.mshelp.be/img/Ent.0Part2UpdatingtheEntitymodelfromadat_DDB5/image_thumb_3.png" width="541" height="484" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://mshelp.be/entity-framework-4-0-part2-updating-the-entity-model-from-a-database-328.htm/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Entity Framework 4.0 &#8211; Part1: How to create a model from a database</title>
		<link>http://mshelp.be/entity-framework-4-0-part1-how-to-create-a-model-from-a-database-325.htm</link>
		<comments>http://mshelp.be/entity-framework-4-0-part1-how-to-create-a-model-from-a-database-325.htm#comments</comments>
		<pubDate>Fri, 19 Mar 2010 23:13:43 +0000</pubDate>
		<dc:creator>Sven</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://mshelp.be/entity-framework-4-0-part1-how-to-create-a-model-from-a-database-325.htm</guid>
		<description><![CDATA[These tutorials are built using Visual Studio 2010 RC and .NET 4.0. RC. This means that Entity Framework 4.0 is used. At the moment of writing this, VS2010 and .NET 4.0 are not yet released as RTM so information provided in this post could change in the future. In this series of blog posts Iâ€™ll [...]]]></description>
			<content:encoded><![CDATA[<p>These tutorials are built using Visual Studio 2010 RC and .NET 4.0. RC. This means that Entity Framework 4.0 is used. At the moment of writing this, VS2010 and .NET 4.0 are not yet released as RTM so information provided in this post could change in the future.</p>
<p>In this series of blog posts Iâ€™ll explain to you how to work with Microsoftâ€™s ORM, Entity Framework. Version 4.0 is used during the tutorials. I didnâ€™t really blog that much before on Entity Framework because I thought the concept and usage was not ready. Now with the new release EF, I feel much more comfortable evangelizing it. Following, Iâ€™ll explain to you how you can create an entity framework model based on an already existing database. </p>
<p>Letâ€™s start by creating a new console application and add a new file to the project. When the â€œAdd new item windowâ€ comes up, select ADO.NET Entity Data Model.</p>
<p><a href="http://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image.png"><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://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_thumb.png" width="644" height="446" /></a> </p>
<p>Now the wizard will start. This wizard will help you to build up your entity model. Here you have two options:</p>
<ol>
<li>Generate from database: Here the model will be generated based on an existing database with tables. </li>
<li>Empty model: Before Entity Framework 4.0 this didnâ€™t really do much. But now this has changed a lot! From here you can create your own model (using the designer) and even generate a database script (to create the database and tables). How you can start from an empty Entity Framework model will be discussed in an upcoming post. </li>
</ol>
<p><a href="http://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_3.png"><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://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_thumb_3.png" width="542" height="484" /></a> </p>
</p>
<p>So we chose to generate the model from the database. This means we have select our database and tables. The wizard now asks us to select the database.</p>
<p>Iâ€™m going to create a â€œNew Connectionâ€¦â€ because I havenâ€™t used this database before.</p>
<p><a href="http://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_4.png"><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://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_thumb_4.png" width="543" height="484" /></a> </p>
<p>This dialog window isnâ€™t new. If you have worked before with databases in Visual Studio, you should already be familiar with this window. It just asks you to select a server name and a database on that server.</p>
<p><a href="http://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_5.png"><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://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_thumb_5.png" width="333" height="484" /></a> </p>
<p>Once the database has been selected, the wizard will generate the Entity connection string. This is something like a regular database connection string. The only difference is that it contains more information on the Entity Framework model. Make sure that you check â€œSave entity connection string in App.Configâ€. This will save the connection string to an App.Config file.</p>
<p><a href="http://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_6.png"><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://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_thumb_6.png" width="542" height="484" /></a> </p>
<p>Next we need to select the tables where we want to generate entities for. In my demo Iâ€™m only going to work with the Article table. Notice that you can also add database views or stored procedures to your entity model.    <br />Make sure that you check the two checkboxes on this window.</p>
<p>Pluralisation is something new in EF4.0. If you check this box, EF4.0 will pluralize the name of you entity sets based on the Entity name. This will make querying a lot more readable in your code. Before when you had an entity that called Article, you entity set would also be called Article. Now when your entity is called Article, the entity set will be called Articles. The pluralisation mechanism in Visual Studio is actually quite smart! It doesnâ€™t just add an â€˜&#8217;sâ€™ at the end of the entity name. For instance: Category will pluralize to Categories and Ox will even be pluralized to Oxen. How neat is that? For now the pluralisation only works correctly for the English language. No problem though, you can easily create you own pluralisation service where you can add your own words. Dan Rigsby has a nice blog post on this: <a href="http://www.danrigsby.com/blog/index.php/2009/05/19/entity-framework-40-pluralization">Entity Framework 4.0: Pluralization</a></p>
<p><a href="http://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_7.png"><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://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_thumb_7.png" width="542" height="484" /></a>&#160;</p>
<p>Once the model is completely generated, you will see that Visual Studio has created an .edmx file (the entity model) together with its generated code behind class and an App.Config (where we stored the entity connection string).</p>
<p><a href="http://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_8.png"><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://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_thumb_8.png" width="315" height="346" /></a> </p>
<p>If you click on the .edmx file, you will see a diagram of the model.</p>
<p><a href="http://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_9.png"><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://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_thumb_9.png" width="562" height="484" /></a> </p>
</p>
<p>The WPF text editor in Visual Studio 2010 allows us to zoom the model in and out via the scroll wheel on the mouse. If you have a lot of entities in your model, you can easily get a good overview of the diagram. Under the scrollbar you have some different options to alter the view of the diagram. </p>
<p>From top to bottom</p>
<ul>
<li>Zoom in on the diagram </li>
<li>Zoom the diagram to 100% </li>
<li>Zoom out on the diagram </li>
<li>Launch the thumbnail viewer: This allows you to better navigate over the complete diagram </li>
</ul>
<p><a href="http://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_10.png"><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://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_thumb_10.png" width="604" height="484" /></a>&#160;</p>
<p>If you select an entity and click on the mapping details you will see how the table fields are mapped to the properties of the entity. If you want you can change details in the properties window. Information that was set on the table fields is also set on the entity properties. For example if you create a field in the table with a max length of 100 (varchar(100)) this will also be set in the entity property. This is not something that you will find back in the generated code behind class of the model. Itâ€™s actually stored in the conceptual model.</p>
<p><a href="http://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_11.png"><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://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_thumb_11.png" width="597" height="484" /></a> </p>
<p><a href="http://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_12.png"><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://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_thumb_12.png" width="458" height="337" /></a>&#160;</p>
<p>Now letâ€™s write some code to retrieve data from the database. As you can see, you only need to create a new instance of you entity model. Then you can retrieve your records by calling the entity set of you entity. See how easy this is?</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:DFDE9937-D816-47f4-A306-7B60D5CE5AC0:dcaed1a3-083a-466c-89a1-55d16447ade7" class="wlWriterEditableSmartContent">
<pre class="brush: csharp; gutter: true; first-line: 1; tab-size: 4;  toolbar: true; ">class Program
    {
        static void Main(string[] args)
        {
            using (var dbentities = new DemoDBEntities())
            {
                foreach (var article in dbentities.Articles)
                {
                    Console.WriteLine(string.Format(&quot;Name: {0}&quot;,article.Name));
                    Console.WriteLine(string.Format(&quot;Description: {0}&quot;,article.Description));
                    Console.WriteLine(string.Format(&quot;Price: {0}&quot;,article.Price));
                    Console.WriteLine(string.Format(&quot;Stock: {0}&quot;,article.Stock));
                    Console.WriteLine();
                }
            }
            Console.ReadLine();
        }
    }</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p><a href="http://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_13.png"><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://www.mshelp.be/img/Ent.0Part1Howtocreateamodelfromadatabase_2F0/image_thumb_13.png" width="644" height="331" /></a> </p>
<p>Hope this was informative!</p>
<p>If you have any questions or remarks, please let me know..</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fmshelp.be%2fentity-framework-4-0-part1-how-to-create-a-model-from-a-database-325.htm"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fmshelp.be%2fentity-framework-4-0-part1-how-to-create-a-model-from-a-database-325.htm" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://mshelp.be/entity-framework-4-0-part1-how-to-create-a-model-from-a-database-325.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>.NET 4.0 training kit &#8211; February release</title>
		<link>http://mshelp.be/net-4-0-training-kit-february-release-308.htm</link>
		<comments>http://mshelp.be/net-4-0-training-kit-february-release-308.htm#comments</comments>
		<pubDate>Sun, 14 Feb 2010 22:08:15 +0000</pubDate>
		<dc:creator>Sven</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://mshelp.be/net-4-0-training-kit-february-release-308.htm</guid>
		<description><![CDATA[A bit late but some days ago they released the updated Visual Studio 2010 and .NET 4.0 training kit. Enjoy this new fine release! Follow the link below to download Visual Studio 2010 and .NET Framework 4 Training Kit &#8211; February Release]]></description>
			<content:encoded><![CDATA[<p>A bit late but some days ago they released the updated Visual Studio 2010 and .NET 4.0 training kit. Enjoy this new fine release! Follow the link below to download</p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=752CB725-969B-4732-A383-ED5740F02E93&amp;displaylang=en">Visual Studio 2010 and .NET Framework 4 Training Kit &#8211; February Release</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mshelp.be/net-4-0-training-kit-february-release-308.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>COM interop improvements with C#4.0</title>
		<link>http://mshelp.be/com-interop-improvements-with-c4-0-307.htm</link>
		<comments>http://mshelp.be/com-interop-improvements-with-c4-0-307.htm#comments</comments>
		<pubDate>Tue, 09 Feb 2010 22:46:27 +0000</pubDate>
		<dc:creator>Sven</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[COM Interop]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://mshelp.be/com-interop-improvements-with-c4-0-307.htm</guid>
		<description><![CDATA[I already did a blog post about this some time ago: Better Office COM interop thanks to named and optional parameters Here I talked mainly on how named and optional parameters make life easier for Office developers. This focus was more on that. But actually there are a some other points that didnâ€™t get enough [...]]]></description>
			<content:encoded><![CDATA[<p>I already did a blog post about this some time ago: <a href="http://mshelp.be/better-office-com-interop-thanks-to-named-and-optional-parameters-272.htm">Better Office COM interop thanks to named and optional parameters</a></p>
<p>Here I talked mainly on how named and optional parameters make life easier for Office developers. This focus was more on that. But actually there are a some other points that didnâ€™t get enough attention. Here are some other great improvements specifically for COM interop.</p>
<ul>
<li>No more meaningless ref parameters. </li>
<li>Better indexer support, property accessing. No specific get/set needed anymore. </li>
<li>No more need for casting, we can use dynamic binding thanks to the Dynamic class. </li>
</ul>
<p>I have found a screencast by <a href="http://blogs.msdn.com/samng">Sam Ng</a> who explains all this in about 10min.</p>
<p> <script src="http://msdn.microsoft.com/objectforward/default.aspx?type=VideoPlayer&amp;video=http%3A%2F%2Fdownload.microsoft.com%2Fdownload%2F1%2F8%2F3%2F18391C4D-DC57-45E8-A0D2-37F4919F34BE%2FHDI-MSDN-VCSharp-winvideo-ComInterop.wmv&amp;thumb=http%3A%2F%2Fi.msdn.microsoft.com%2Fee460939.CSharp4ComInterop_400X282(en-us%252cMSDN.10).png&amp;title=&amp;width=400&amp;height=400" type="text/javascript"></script><br />
<h5>Link to the original post â€“&gt; <a href="http://msdn.microsoft.com/en-us/vcsharp/ee460939.aspx">How Do I: COM Interop and Office in C# 4.0?</a></h5>
]]></content:encoded>
			<wfw:commentRss>http://mshelp.be/com-interop-improvements-with-c4-0-307.htm/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Better Office COM interop thanks to named and optional parameters</title>
		<link>http://mshelp.be/better-office-com-interop-thanks-to-named-and-optional-parameters-272.htm</link>
		<comments>http://mshelp.be/better-office-com-interop-thanks-to-named-and-optional-parameters-272.htm#comments</comments>
		<pubDate>Sat, 09 Jan 2010 13:42:30 +0000</pubDate>
		<dc:creator>Sven</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[COM Interop]]></category>

		<guid isPermaLink="false">http://mshelp.be/better-office-com-interop-thanks-to-named-and-optional-parameters-272.htm</guid>
		<description><![CDATA[In my last screencast I showed you how to work with two new features in C#4.0 which are named and optional parameters. Now in this post I will show you another way how you can benefit from these new features. Remember when you had to create these Microsoft Word document with the Office interop API [...]]]></description>
			<content:encoded><![CDATA[<p>In my last <a href="http://mshelp.be/screencast-net-4-0-named-and-optional-parameters-268.htm">screencast</a> I showed you how to work with two new features in C#4.0 which are named and optional parameters. Now in this post I will show you another way how you can benefit from these new features. </p>
<p>Remember when you had to create these Microsoft Word document with the Office interop API and had to pass all these tedious by ref parameters. Things you absolutely didnâ€™t care about! But anyway the Office COM Interop assemblies were expecting them. Thanks to named and optional parameters this will all go away!</p>
<p>So letâ€™s first start with adding a reference to the Microsoft Office Word Interop assembly.</p>
<p><a href="http://www.mshelp.be/img/BetterOfficeCOMinteropthankstonamedandop_CE43/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.mshelp.be/img/BetterOfficeCOMinteropthankstonamedandop_CE43/image_thumb.png" width="244" height="207" /></a> </p>
<p>Following is the code we had to write before we could use named and optional parameters.</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:2d8e2899-89cc-437c-bc41-d94ce7bdafd5" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">class</span><span style="color: #000000;"> Program
{
   </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> Main(</span><span style="color: #0000FF;">string</span><span style="color: #000000;">[] args)
   {
       </span><span style="color: #0000FF;">object</span><span style="color: #000000;"> missing </span><span style="color: #000000;">=</span><span style="color: #000000;"> System.Reflection.Missing.Value;
       </span><span style="color: #0000FF;">object</span><span style="color: #000000;"> visible </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">true</span><span style="color: #000000;">;

       </span><span style="color: #008000;">//</span><span style="color: #008000;">Create instance of Word application</span><span style="color: #008000;">
</span><span style="color: #000000;">       Word.Application wordApp </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Microsoft.Office.Interop.Word.Application();
       </span><span style="color: #008000;">//</span><span style="color: #008000;">Make the Word application visible</span><span style="color: #008000;">
</span><span style="color: #000000;">       wordApp.Visible </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">true</span><span style="color: #000000;">;
       </span><span style="color: #008000;">//</span><span style="color: #008000;">Create instance of Word document</span><span style="color: #008000;">
</span><span style="color: #000000;">       Word.Document wordDocument;

       </span><span style="color: #008000;">//</span><span style="color: #008000;">Add document to document collection of word instance</span><span style="color: #008000;">
</span><span style="color: #000000;">       wordDocument </span><span style="color: #000000;">=</span><span style="color: #000000;"> wordApp.Documents.Add(</span><span style="color: #0000FF;">ref</span><span style="color: #000000;"> missing, </span><span style="color: #0000FF;">ref</span><span style="color: #000000;"> missing, </span><span style="color: #0000FF;">ref</span><span style="color: #000000;"> missing,</span><span style="color: #0000FF;">ref</span><span style="color: #000000;"> visible);
       </span><span style="color: #008000;">//</span><span style="color: #008000;">Type text in our Word document</span><span style="color: #008000;">
</span><span style="color: #000000;">       wordApp.Selection.TypeText(</span><span style="color: #800000;">"</span><span style="color: #800000;">This is my dynamically created word document</span><span style="color: #800000;">"</span><span style="color: #000000;">);

       Console.WriteLine(</span><span style="color: #800000;">"</span><span style="color: #800000;">Done</span><span style="color: #800000;">"</span><span style="color: #000000;">);
       Console.In.ReadLine();

   }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>As you can see we had to define this missing object and pass it when we added our Word document to the documents collection of the Microsoft Word application instance. This doesnâ€™t mean that much but hey we had to add it anyway to make it work. Now with optional parameters this isnâ€™t needed anymore. We can just leave them out!</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:ff73f3c9-03f6-47aa-a967-21171c0c2d52" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #000000;">wordDocument </span><span style="color: #000000;">=</span><span style="color: #000000;"> wordApp.Documents.Add(</span><span style="color: #0000FF;">ref</span><span style="color: #000000;"> visible);</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Will this do the trick then? Well not really because now you have removed 3 missing objects and are left with the visible Boolean. To make it really work, we have to define which parameter the visible object represents. This can be done with the named parameter feature. Now the method call will look like this:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:a36b2d85-a81b-4e94-8610-501485058adf" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #000000;">wordDocument </span><span style="color: #000000;">=</span><span style="color: #000000;"> wordApp.Documents.Add(Visible:</span><span style="color: #0000FF;">ref</span><span style="color: #000000;"> visible);</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Isnâ€™t this so cool? But wait it gets even better. Another new feature of C# 4.0 is that we donâ€™t need to explicitly pass parameters by reference anymore. So we can clean our code up some more. Finally we will end up with this piece of code, which is by the way much more readable.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:d0e0e576-4305-49df-97cc-72262b72553f" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">class</span><span style="color: #000000;"> Program
{
   </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> Main(</span><span style="color: #0000FF;">string</span><span style="color: #000000;">[] args)
   {
       </span><span style="color: #008000;">//</span><span style="color: #008000;">Create instance of Word application</span><span style="color: #008000;">
</span><span style="color: #000000;">       Word.Application wordApp </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Microsoft.Office.Interop.Word.Application();
       </span><span style="color: #008000;">//</span><span style="color: #008000;">Make the Word application visible</span><span style="color: #008000;">
</span><span style="color: #000000;">       wordApp.Visible </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">true</span><span style="color: #000000;">;
       </span><span style="color: #008000;">//</span><span style="color: #008000;">Create instance of Word document</span><span style="color: #008000;">
</span><span style="color: #000000;">       Word.Document wordDocument;

       </span><span style="color: #008000;">//</span><span style="color: #008000;">Add document to document collection of word instance</span><span style="color: #008000;">
</span><span style="color: #000000;">       wordDocument </span><span style="color: #000000;">=</span><span style="color: #000000;"> wordApp.Documents.Add(Visible:</span><span style="color: #0000FF;">true</span><span style="color: #000000;">);
       </span><span style="color: #008000;">//</span><span style="color: #008000;">Type text in our Word document</span><span style="color: #008000;">
</span><span style="color: #000000;">       wordApp.Selection.TypeText(</span><span style="color: #800000;">"</span><span style="color: #800000;">This is my dynamically created word document</span><span style="color: #800000;">"</span><span style="color: #000000;">);

       Console.WriteLine(</span><span style="color: #800000;">"</span><span style="color: #800000;">Done</span><span style="color: #800000;">"</span><span style="color: #000000;">);
       Console.In.ReadLine();

   }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
]]></content:encoded>
			<wfw:commentRss>http://mshelp.be/better-office-com-interop-thanks-to-named-and-optional-parameters-272.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Screencast: .net 4.0 Named and Optional parameters</title>
		<link>http://mshelp.be/screencast-net-4-0-named-and-optional-parameters-268.htm</link>
		<comments>http://mshelp.be/screencast-net-4-0-named-and-optional-parameters-268.htm#comments</comments>
		<pubDate>Thu, 31 Dec 2009 15:08:38 +0000</pubDate>
		<dc:creator>Sven</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Screencast]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://mshelp.be/screencast-net-4-0-named-and-optional-parameters-268.htm</guid>
		<description><![CDATA[Since I installed Visual Studio 2010 Beta 2, Iâ€™m no investigating all the new features of .NET 4.0. I did a short video on the new named and optional parameters. The quality of the video is not fantastic, sorry for that. If you got any tips on proper encoding and better places where I can [...]]]></description>
			<content:encoded><![CDATA[<p>Since I installed Visual Studio 2010 Beta 2, Iâ€™m no investigating all the new features of .NET 4.0. I did a short video on the new named and optional parameters. The quality of the video is not fantastic, sorry for that. If you got any tips on proper encoding and better places where I can host the videos. Please let me know.</p>
<p>Hopefully youâ€™ll like it.</p>
<p><iframe src="http://www.microsoft.com/belux/msdn/nl/chopsticks/player.aspx?id=1526" frameborder="0" width="493px" height="385px" scrolling="no" marginheight="0" marginwidth="0" ></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://mshelp.be/screencast-net-4-0-named-and-optional-parameters-268.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Getting started with Visual Studio 2010 and TFS2010</title>
		<link>http://mshelp.be/getting-started-with-visual-studio-2010-and-tfs2010-267.htm</link>
		<comments>http://mshelp.be/getting-started-with-visual-studio-2010-and-tfs2010-267.htm#comments</comments>
		<pubDate>Mon, 28 Dec 2009 12:02:09 +0000</pubDate>
		<dc:creator>Sven</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://mshelp.be/getting-started-with-visual-studio-2010-and-tfs2010-267.htm</guid>
		<description><![CDATA[A new year is just around the corner and itâ€™s also time to start working with Visual Studio 2010, Team Foundation Server 2010 and .NET4.0. Itâ€™s packed full with new and cool features. Maybe Iâ€™ll even do some posts on these new features. But how can you get started? Well thatâ€™s not too difficult. Microsoft [...]]]></description>
			<content:encoded><![CDATA[<p>A new year is just around the corner and itâ€™s also time to start working with Visual Studio 2010, Team Foundation Server 2010 and .NET4.0. Itâ€™s packed full with new and cool features. Maybe Iâ€™ll even do some posts on these new features.</p>
<p>But how can you get started? Well thatâ€™s not too difficult. Microsoft has given us a lot of new VPC images for Christmas. Check out the list</p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=426cdffc-53b5-46a5-89d3-e2ecd23570c6">Visual Studio 2010 Beta 2 and TFS2010 (Hyper-V)</a></p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=27d91e63-e33b-4cef-a331-f20d343da9de">Visual Studio 2010 Beta 2 and TFS2010 (Windows [7] Virtual PC)</a></p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=540777b0-cbd7-485e-bde5-23a1d4f442e0">Visual Studio 2010 Beta 2 and TFS2010 (Virtual PC 2007 SP1)</a></p>
<p>Want to start setting up an image yourself and just want to have the ISOs of Visual Studio 2010 Beta 2 and Team Foundatsion Server 2010 Beta 2? No problem, Microsoft also released these bits on the Microsoft Download site:</p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=630de613-7b65-4179-9da4-04def4bf9ebc">Microsoft Visual Studio 2010 Premium Beta 2</a></p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=a80dfb5d-51c6-4778-8656-a9ff29d3a132">Microsoft Visual Studio 2010 Professional Beta 2</a></p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=dc333ac8-596d-41e3-ba6c-84264e761b81">Microsoft Visual Studio 2010 Ultimate Beta 2</a></p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=6c70fd8f-615e-4203-a028-acb2c2b8b88f">Microsoft Visual Studio Team Foundation Server 2010 Beta 2</a> (Some help is also provided: <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=2d531219-2c39-4c69-88ef-f5ae6ac18c9f">Team Foundation Installation Guide 2010</a>)</p>
<p>Once everything is set up and installed, you probably want to start immediately trying out this new IDE, right? Check out this cool training kit full of demoâ€™s, videos, hands on labs <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=752cb725-969b-4732-a383-ed5740f02e93">Visual Studio 2010 and .NET Framework 4 Training Kit</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mshelp.be/getting-started-with-visual-studio-2010-and-tfs2010-267.htm/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New Version of Visual Studio announced, Hello Visual Studio 2010, Hello .NET 4.0</title>
		<link>http://mshelp.be/new-version-of-visual-studio-announced-hello-visual-studio-2010-hello-net-40-202.htm</link>
		<comments>http://mshelp.be/new-version-of-visual-studio-announced-hello-visual-studio-2010-hello-net-40-202.htm#comments</comments>
		<pubDate>Sat, 04 Oct 2008 10:08:52 +0000</pubDate>
		<dc:creator>Sven</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Visual Studio Team Systems]]></category>

		<guid isPermaLink="false">http://mshelp.be/new-version-of-visual-studio-announced-hello-visual-studio-2010-hello-net-40-202.htm</guid>
		<description><![CDATA[And I can only say that I&#8217;m really looking forward to these new releases. I&#8217;ll try to give a summary of the video in this post. Like Norman Guagagno is saying VSTS 2010 will focus a lot more on ALM (Application Lifecycle Management), Architecture, Testing and several more things. With better ALM they want to [...]]]></description>
			<content:encoded><![CDATA[<p>And I can only say that I&#8217;m really looking forward to these new releases. I&#8217;ll try to give a summary of the video in this post. Like Norman Guagagno is saying VSTS 2010 will focus a lot more on ALM (Application Lifecycle Management), Architecture, Testing and several more things. With better ALM they want to involve all the different participants more in the same process and don&#8217;t integrate all the different work into a single process. What does this really mean? There are many different functions in an application lifecycle. For instance you have the analyst, the architect, the developer, the tester etc. The way it works now is that the analyst does the analysis, the architect does his logical design, the developer does his developing and the tester does his testing. Most of the time they do this in their own environment. This can sometimes lead to problems. They developer doesn&#8217;t entirely understand the logical design , the developer cannot reproduce a certain bug tester has gotten. With VSTS2010 they want all this to happen in the same environment. This will solve a lot of problems I think. Microsoft is also putting a lot of effort into creating the necessary tools ad features to make this all possible. In example there will be a lot of new tools for the architect. Microsoft has embraced UML so there will a tool for creating UML diagrams. There will also be a tool for creating better models, logical models that can even have constraints (f.e. you cannot link a presentation layer model directly to a database layer model). Another thing that I really like is the hysterical debugging. Like I said earlier sometimes a developer cannot reproduce a certain bug. Now if a tester and a developer would have access to the same environment or tool they would have some common ground. And this way it is possible to abstract environment data and share this through that same environment. This way the developer could get that abstracted data and entirely recreate the situation the tester was in. </p>
<p>There will also be several improvements to the already existing TFS(Team Foundation Server). There will be a better way to control the source, the work items, better dashboards to control what is in the TFS etc&#8230;</p>
<p>I know I didn&#8217;t talk a lot about .NET4.0 but this was a post purely on the new tool to use the new framework. The framework will be covered later.</p>
<p>If you want more details be sure to check out the following videos&#8217;s!</p>
<p><iframe height="325" src="http://channel9.msdn.com/posts/Dan/429924/player/" frameborder="0" width="320" scrolling="no"></iframe><br /><a href="http://channel9.msdn.com/posts/Dan/Norman-Guadagno-Announcing-Visual-Studio-Team-System-2010/">Norman Guadagno: Announcing Visual Studio Team System 2010</a></p>
<p><strong>Architecture Day</strong> (Tuesday, September 30th):<br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Cameron-Skinner-Visual-Studio-Team-System-2010-Architecture/">Cameron Skinner: Visual Studio Team System 2010 &#8211; Architecture</a><br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Top-down-design-with-Visual-Studio-Team-System-2010/">&#8220;Top-down&#8221; design with Visual Studio Team System 2010</a><br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Bottom-up-Design-with-Visual-Studio-Team-System-2010-Architect/">&#8220;Bottom-up&#8221; Design with Visual Studio Team System 2010 Architect</a><br />- <a href="http://channel9.msdn.com/shows/ARCast.TV/ARCastTV-Peter-Provost-on-whats-coming-for-Architects-in-Visual-Studio-Team-System/">ARCast.TV &#8211; Peter Provost on whatâ€™s coming for Architects in Visual Studio Team System</a><br /><strong>Business Alignment </strong>(Wednesday, October 1st):<br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Achieving-Business-Alignment-with-Visual-Studio-Team-System-2010/">Achieving Business Alignment with Visual Studio Team System 2010</a><br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Agile-Planning-Templates-in-Visual-Studio-Team-System-2010/">Agile Planning Templates in Visual Studio Team System 2010</a><br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Enterprise-Project-Management-with-Visual-Studio-Team-System-2010/">Enterprise Project Management with Visual Studio Team System 2010</a><br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Requirements-Management-and-Traceability-with-Visual-Studio-Team-System-2010/">Requirements Management and Traceability with Visual Studio Team System 2010</a><br /><strong>Software Quality</strong> (Thursday, October 2nd):<br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Better-Software-Quality-with-Visual-Studio-Team-System-2010/">Better Software Quality with Visual Studio Team System 2010</a><br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Manual-Testing-with-Visual-Studio-Team-System-2010/">Manual Testing with Visual Studio Team System 2010</a><br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Historical-Debugger-and-Test-Impact-Analysis-in-Visual-Studio-Team-System-2010/">Historical Debugger and Test Impact Analysis in Visual Studio Team System 2010</a><br /><strong>Team Foundation Server </strong>(Friday, October 3rd):<br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Brian-Harry-Team-Foundation-Server-2010/">Brian Harry: Team Foundation Server 2010</a><br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Branching-and-Merging-Visualization-with-Team-Foundation-Server-2010/">Branching and Merging Visualization with Team Foundation Server 2010</a><br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Enterprise-Team-Foundation-Server-Management-with-Mario-Rodriguez/">Enterprise Team Foundation Server Management with Mario Rodriguez</a><br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Team-Foundation-Server-2010-Setup-and-Administration/">Team Foundation Server 2010 Setup and Administration</a><br />- <a href="http://channel9.msdn.com/posts/VisualStudio/An-early-look-at-Team-Foundation-Build-2010-with-Jim-Lamb/">An early look at Team Foundation Build 2010 with Jim Lamb</a><br />- <a href="http://channel9.msdn.com/posts/VisualStudio/A-first-look-at-Visual-Studio-Team-System-Web-Access-2010/">A first look at Visual Studio Team System Web Access 2010</a><br />- <a href="http://channel9.msdn.com/posts/VisualStudio/Update-on-Team-Foundation-Server-Migration-and-Synchronization/">Update on Team Foundation Server Migration and Synchronization</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mshelp.be/new-version-of-visual-studio-announced-hello-visual-studio-2010-hello-net-40-202.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

