<?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>Gary Pretty's Blog &#187; Entity Fraemwork</title>
	<atom:link href="http://blog.garypretty.co.uk/index.php/category/entity-fraemwork/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.garypretty.co.uk</link>
	<description>.Net Development &#38; General Tech Related News</description>
	<lastBuildDate>Sat, 04 Feb 2012 00:32:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Multi-Select List Box in ASP.NET MVC</title>
		<link>http://blog.garypretty.co.uk/index.php/2010/02/26/multi-select-list-box-in-asp-net-mvc/</link>
		<comments>http://blog.garypretty.co.uk/index.php/2010/02/26/multi-select-list-box-in-asp-net-mvc/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 17:13:57 +0000</pubDate>
		<dc:creator>Gary Pretty</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Entity Fraemwork]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://blog.garypretty.co.uk/?p=245</guid>
		<description><![CDATA[Recently I have been working on an MVC site using the Entity Framework.  I have some related entities in my EF model, as show below in the form of &#8220;Reader&#8221; and &#8220;Category&#8221;, and the relationship between them, i.e. many to many. When it came to proucing a view and action to perofrm the Create Reader &#8230; </p><p><a class="more-link block-button" href="http://blog.garypretty.co.uk/index.php/2010/02/26/multi-select-list-box-in-asp-net-mvc/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>Recently I have been working on an MVC site using the Entity Framework. </p>
<p style="text-align: center;">I have some related entities in my EF model, as show below in the form of &#8220;Reader&#8221; and &#8220;Category&#8221;, and the relationship between them, i.e. many to many.<br />
<img class="aligncenter size-medium wp-image-248" style="margin: 10px; border: black 1px solid;" title="EF Model" src="http://blog.garypretty.co.uk/wp-content/model-283x300.png" alt="" width="283" height="300" /></p>
<p>When it came to proucing a view and action to perofrm the Create Reader action, I was somewhat puzzled as to how I could allow the user to select one or more categories for a reader. </p>
<p>I started by having a view model that contained a list of all possible categories and then looping around these in my view and writing a check box out for each one.  When the form was submitted I looked through the form collection to find if any of the category check boxes had been selected.  I didn&#8217;t like this one bit and so I set out to find a cleaner way of carrying it out.</p>
<p>After some (quite a lot actually) searching, I stumbled accross the MultiSelectList type, which I could use in my ViewModel and then allow the default model binding to step in and do the leg work for me <img src='http://blog.garypretty.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Great!</p>
<p>So, I created a view model, a simplified version of which you can see below;</p>
<blockquote><p>    public class ReaderCreateViewModel : CustomViewModelBase<br />
    {</p>
<p>        public ReaderCreateViewModel()<br />
        {<br />
            ReaderDetails = new Reader();<br />
            CategoriesList = GetCategories(null);<br />
        }</p>
<p>        public Reader ReaderDetails { get; set; }<br />
        public MultiSelectList CategoriesList { get; private set; }<br />
        public int[] SelectedCategories { get; set; }</p>
<p>        public MultiSelectList GetCategories(int[] selectedValues)<br />
        {<br />
            var te = new myEntities();<br />
            List&lt;Category&gt; categories = te.Categories.ToList();<br />
            return new MultiSelectList(categories, &#8220;id&#8221;, &#8220;Name&#8221;, selectedValues);<br />
        }<br />
    }</p></blockquote>
<p> As you can see from the code above, the view model contains my Reader entity, a list of type MultiSelectList, which is a list of available categories and an array of integers which represent the Id of any selected Categories.</p>
<p>Then to add a listbox to my view that will bind the MultiSelectList, I simply insert the following into my view.</p>
<blockquote><p>            &lt;p&gt;<br />
             &lt;label for=&#8221;SelectedCategories&#8221;&gt;Categories:&lt;/label&gt;<br />
        &lt;%= Html.ListBox(&#8220;SelectedCategories&#8221;, Model.CategoriesList) %&gt;<br />
            &lt;/p&gt;</p></blockquote>
<p>Finally in my controller, I can simply check the SelectedItems object in my model for any selected Ids and add them to the Reader Categories list like this;</p>
<blockquote><p>            if (model.SelectedCategories != null)<br />
            {<br />
                foreach (var selectedCat in model.SelectedCategories)<br />
                {<br />
                    int selectedCatId = selectedCat;<br />
                    Category category = DataContext.Categories.Where(c =&gt; c.id                  == selectedCatId).FirstOrDefault();<br />
                    reader.Categories.Add(category);<br />
                }<br />
            }</p></blockquote>
<p>And that&#8217;s it.  Now there is probably a much better way of doing all or some of the above, but this worked perfectly for me when I needed it, so I hope it helps someone else out as well.  The final multi-select list box looked something like this;</p>
<p><a href="http://blog.garypretty.co.uk/wp-content/listbox.bmp"><img class="aligncenter size-full wp-image-250" title="listbox" src="http://blog.garypretty.co.uk/wp-content/listbox.bmp" alt="" /></a></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/ASP.NET+MVC' rel='tag' target='_self'>ASP.NET MVC</a>, <a class='technorati-link' href='http://technorati.com/tag/Entity+Framework' rel='tag' target='_self'>Entity Framework</a>, <a class='technorati-link' href='http://technorati.com/tag/MVC' rel='tag' target='_self'>MVC</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://blog.garypretty.co.uk/index.php/2010/02/26/multi-select-list-box-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Entity Framework Improvements in .Net 4.0 &#8211; Summary &amp; Links</title>
		<link>http://blog.garypretty.co.uk/index.php/2009/05/13/entity-framework-improvements-in-net-40-summary-links/</link>
		<comments>http://blog.garypretty.co.uk/index.php/2009/05/13/entity-framework-improvements-in-net-40-summary-links/#comments</comments>
		<pubDate>Wed, 13 May 2009 11:24:42 +0000</pubDate>
		<dc:creator>Gary Pretty</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Betas]]></category>
		<category><![CDATA[Entity Fraemwork]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[eneity framework]]></category>

		<guid isPermaLink="false">http://blog.garypretty.co.uk/?p=84</guid>
		<description><![CDATA[I have used the entity framework in a few projects using .Net 3.5, but we were promised that there was much more to come in the next version which is shipping with .Net 4.0 and with quite a few announcements recently from the ADO.NET Team, I thought I would summarise and provide some links (at &#8230; </p><p><a class="more-link block-button" href="http://blog.garypretty.co.uk/index.php/2009/05/13/entity-framework-improvements-in-net-40-summary-links/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>I have used the entity framework in a few projects using .Net 3.5, but we were promised that there was much more to come in the next version which is shipping with .Net 4.0 and with quite a few announcements recently from the ADO.NET Team, I thought I would summarise and provide some links (at the bottom of the post) for you to get some more detailed info if you are interested.</p>
<p><strong>Model First</strong></p>
<p>This is something that I am really excited about and something that has long been needed IMHO.</p>
<p>In .Net 3.5 you could take a database and generate your entity framework model from it.  In .Net 4.0 , however, it is possible to create your model first and then generate DDL for creating your database from your model. </p>
<p>This is all fantastic and I can see me using this method alot, but whats even better is the fact that you will also have the ability to customise the DDL generation step yourself to suit your own needs.  For example, the default generation would be to generate a table per entity type, but you may have several entity classes that inherit from a parent class and in this instance you may want to modify the generator to produce a table per hierarchy structure for your database.</p>
<p><strong>Deferred Loading</strong></p>
<p>One of the things that people wish was available in the Entity Framework is deferred loading as it is in Linq to SQL. Well, now thanks to the ADO.Net team listening to the feedback, it is.  Previously, if you had a <em>Customer </em>object that contained <em>Orders</em> for each customer, you needed to explicitly call a <strong>Load </strong>method on the <em>Customer </em>object to be able to use the <em>Order </em>objects associated with it.</p>
<p>Now though, the following is possible;</p>
<blockquote>
<pre class="csharpcode"><span class="kwrd">using</span> (<span style="color: #4f9d9d;">NorthwindEntities</span> db = <span class="kwrd">new</span> <span style="color: #4e9a9a;">NorthwindEntities</span>())
{
    db.ContextOptions.DeferredLoadingEnabled = <span class="kwrd">true</span>;

    <span class="kwrd">foreach</span> (<span style="color: #4e9a9a;">Customer</span> c <span class="kwrd">in</span> db.Customers)
    {
        <span class="kwrd">if</span> (c.Orders.Count &gt; 10)
        {
            SendLoyaltyRewardToCustomer(c);
        }
    }
}</pre>
</blockquote>
<p>In the simple example above, you will notice that you do not need to explicitly load any Orders, but simply set the <em>DeferredLoadingEnabled </em>flag to true (this is off by default, but apparently there are ways to change this).</p>
<p><strong>General Entity Framework Improvements</strong></p>
<p>The following is a list from a recent post on the ADO.Net Team Blog of other key improvements coming to the Framework in this version;</p>
<ol>
<li>
<ol>
<li><strong>Development Approaches</strong>
<ol>
<li>Model First development –  We’ve added functionality to the ADO.NET Entity Data Model designer to start from a Model and then have T-SQL and customized code generated.</li>
<li>Testing applications that use the Entity Framework – Along with the patterns above we’ve added an interface, along with guidance, that enables better testability of applications that use the Entity Framework.</li>
</ol>
<p><strong>Architectural Concerns</strong></p>
<ol>
<li>Persistence Ignorance – Enabling developers to use their own classes without needing to introduce interfaces or other elements specific to the Entity Framework.</li>
<li>Applications Patterns – Discussing patterns like the Repository and UnitOfWork patterns with guidance on how to use them with the Entity Framework</li>
<li>Building N-Tier applications with the Entity Framework – Adding API’s and templates that make building N-Tier applications with the Entity Framework much easier.</li>
</ol>
<p><strong>Entity Framework Improvements</strong></p>
<ol>
<li>Customization of Code Generation – Integration with the ADO.NET Entity Framework Designer and T4 Templates in Visual Studio to provide developer controlled code generation.</li>
<li>Small things that make development of applications simpler – Adding things like Pluralization and Singularlization in the model, lazy loading, and more stored procedure mapping make building applications that use the Entity Framework much easier.</li>
<li>Customizing Queries – Adding support for existing LINQ operators, recognizing a larger set of patterns with LINQ, writing model defined functions along with the ability to use these in LINQ, and a number of other ways to create and customize queries.</li>
<li>SQL Generation Readability Improvements – Improving the readability, along with TSQL performance optimizations, of the generated queries to make it much easier to understand what is happening</li>
<li>And much, much more</li>
</ol>
</li>
</ol>
</li>
</ol>
<p> </p>
<p><strong>Useful Links</strong></p>
<p>The ADO.Net team have said that they have many mroe detailed posts on the way in the next couple of weeks so it&#8217;s well worth keeping an eye on <a href="http://blogs.msdn.com/adonet/">their blog</a>.  Plus, we should soon see a beta of Visual Studio 2010 and .Net 4.0 which should contain some of the aforementioned features.  I will be posting here when that&#8217;s released so keep an eye out for that.</p>
<p><a href="http://blogs.msdn.com/adonet/archive/2009/05/12/sneak-preview-deferred-loading-in-entity-framework-4-0.aspx">ADO.Net Team Blog Post regarding Deferred Loading</a></p>
<p><a href="http://blogs.msdn.com/adonet/archive/2009/05/12/sneak-preview-model-first-in-the-entity-framework-4-0.aspx">ADO.Net Team Blog Post reagrding Model First in EF</a></p>
<p><a href="http://blogs.msdn.com/adonet/">ADO.Net Team Blog</a></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/.NET+4.0' rel='tag' target='_self'>.NET 4.0</a>, <a class='technorati-link' href='http://technorati.com/tag/ADO.NET' rel='tag' target='_self'>ADO.NET</a>, <a class='technorati-link' href='http://technorati.com/tag/eneity+framework' rel='tag' target='_self'>eneity framework</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://blog.garypretty.co.uk/index.php/2009/05/13/entity-framework-improvements-in-net-40-summary-links/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
PHP Fatal error:  Call to undefined function curl_init() in C:\WebSites\Gary\garypretty.co.uk\blog\wp-content\plugins\twitter-tools\twitteroauth.php on line 201

