<?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>PeterKellner.net &#187; ASP.NET 2.0</title>
	<atom:link href="http://peterkellner.net/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://peterkellner.net</link>
	<description>Microsoft Focused, JavaScript,HTML5 (ExtJS, SenchaTouch &#38; Windows 8 Metro)</description>
	<lastBuildDate>Fri, 11 May 2012 16:43:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Details On The ExtJS Application to Build Simple CRUD operation Using Models and Stores</title>
		<link>http://peterkellner.net/2012/04/20/details-on-the-extjs-application-to-build-simple-crud-operation-using-models-and-stores/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=details-on-the-extjs-application-to-build-simple-crud-operation-using-models-and-stores</link>
		<comments>http://peterkellner.net/2012/04/20/details-on-the-extjs-application-to-build-simple-crud-operation-using-models-and-stores/#comments</comments>
		<pubDate>Sat, 21 Apr 2012 00:00:24 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Sencha]]></category>
		<category><![CDATA[SenchaMVC]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=1973</guid>
		<description><![CDATA[&#160;



Part 1
Basics (mostly server side)


Part 2 (this)
ExtJS Client Side Details



&#160;&#160;
In the first article, a very simple updater was build using Sencha’s ExtJS and Microsoft’s Entity Framework Code First.&#160; The focus was really on the server side while the client side project was included for reference.&#160; The client side app was barely discussed.&#160; In this article, [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<table cellspacing="0" cellpadding="2" width="362" border="1">
<tbody>
<tr>
<td valign="top" width="199">Part 1</td>
<td valign="top" width="161"><a href="http://peterkellner.net/2011/11/04/building-an-senchas-extjs-4-0-mvc-application-with-microsofts-asp-net-mvc3-series-basics/">Basics (mostly server side)</a></td>
</tr>
<tr>
<td valign="top" width="219">Part 2 (this)</td>
<td valign="top" width="170"><a href="http://peterkellner.net/2012/04/20/details-on-the-extjs-application-to-build-simple-crud-operation-using-models-and-stores/">ExtJS Client Side Details</a></td>
</tr>
</tbody>
</table>
<p>&#160;&#160;
<p>In the first article, a very simple updater was build using <a href="http://www.sencha.com/">Sencha’s</a> <a href="http://www.sencha.com/products/extjs/">ExtJS</a> and Microsoft’s <a href="http://msdn.microsoft.com/en-us/data/aa937723">Entity Framework</a> <a href="http://blogs.msdn.com/b/adonet/archive/2011/04/11/ef-4-1-released.aspx">Code First</a>.&#160; The focus was really on the server side while the client side project was included for reference.&#160; The client side app was barely discussed.&#160; In this article, we are going to discuss in more detail what is happening on the client side and how the <a href="http://www.sencha.com/products/extjs/">Sencha ExtJS</a> <a href="http://en.wikipedia.org/wiki/JavaScript">JavaScript</a> library helps us to implement these updates.</p>
<p>&#160;</p>
<h2>The Basics</h2>
<p>Let’s start out with some basics rather than jump right in to the real project.&#160;&#160; I think we can all assume the displaying of the data is pretty simple. We just create a store, add some fields, hook it up to a <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.grid.Panel">Ext.grid.Panel</a> and set the store to <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.ElementLoader-cfg-autoLoad">autoload</a> and it all just works.&#160; Updating though does add a little more complexity and for that, we are going to add some structure.&#160; So, let’s take a look at the very basics without any UI at all.</p>
<p>Just by way of reminders, we create two simple services in our project.&#160; One that reads and the other that updates.&#160; For the purpose of this article, those are the three (of four) <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> operations we are going to implement (read,insert and update).&#160; Let’s first implement those operations directly.&#160; Below is a very straight forward JavaScript which basically represents a completely working ExtJS app with a single button in the viewport.&#160; Here is the code below.</p>
<pre class="csharpcode">Ext.Loader.setConfig({ enabled: <span class="kwrd">true</span> });
Ext.require(<span class="str">'Ext.container.Viewport'</span>);

Ext.application({
    name: <span class="str">'AM'</span>,

    controllers: [
        <span class="str">'Users'</span>
    ],

    launch: <span class="kwrd">function</span>() {
        Ext.create(<span class="str">'Ext.container.Viewport'</span>, {
            layout: <span class="str">'border'</span>,
            items: [
                {
                    xtype: <span class="str">'button'</span>,
                    region: <span class="str">'center'</span>,
                    text: <span class="str">'Insert a Record'</span>,
                    handler: <span class="kwrd">function</span> () {
                        <span class="kwrd">var</span> writer = <span class="kwrd">new</span> Ext.data.JsonWriter({
                            type: <span class="str">'json'</span>,
                            encode: <span class="kwrd">false</span>,
                            listful: <span class="kwrd">true</span>,
                            writeAllFields: <span class="kwrd">true</span>,
                            returnJson: <span class="kwrd">true</span>
                        });

                        <span class="kwrd">var</span> reader = <span class="kwrd">new</span> Ext.data.JsonReader({
                            totalProperty: <span class="str">'total'</span>,
                            successProperty: <span class="str">'success'</span>,
                            idProperty: <span class="str">'Id'</span>,
                            root: <span class="str">'Data'</span>,
                            messageProperty: <span class="str">'message'</span>
                        });

                        <span class="kwrd">var</span> proxy = <span class="kwrd">new</span> Ext.data.HttpProxy({
                            reader: reader,
                            writer: writer,
                            type: <span class="str">'ajax'</span>,
                            api: {
                                read: <span class="str">'/UserInfo/Get'</span>,
                                create: <span class="str">'/UserInfo/Create'</span>,
                                update: <span class="str">'/UserInfo/Update'</span>,
                                destroy: <span class="str">'/UserInfo/Delete'</span>
                            },
                            headers: {
                                <span class="str">'Content-Type'</span>: <span class="str">'application/json; charset=UTF-8'</span>
                            }
                        });

                        Ext.define(<span class="str">'MyModel'</span>, {
                            extend: <span class="str">'Ext.data.Model'</span>,
                            fields: [<span class="str">'Id'</span>, <span class="str">'Name'</span>, <span class="str">'Email'</span>],
                            proxy: proxy
                        });

                        Ext.define(<span class="str">'MyStore'</span>, {
                            extend: <span class="str">'Ext.data.Store'</span>,
                            model: <span class="str">'MyModel'</span>,
                            autoLoad: <span class="kwrd">true</span>,
                            paramsAsHash: <span class="kwrd">true</span>,
                            proxy: proxy
                        });

                        <span class="kwrd">var</span> myStore = Ext.create(<span class="str">'MyStore'</span>, {
                        });

                        myStore.add({
                            Name: <span class="str">'TestName'</span>,
                            Email: <span class="str">'TestEmail@Test.com'</span>
                        });

                        myStore.sync();
                    }
                }
            ]
        });
    }
});</pre>
<p>Without going into to much detail, basically, what has been done above is a to create a simple <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Model">model</a> (myModel) which contains a JsonReader and JsonWriter and proxy of course. This model has a couple fields in it (Id,Name and Email), then a simple <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store">store</a> is created that uses this model called myStore.&#160; Once this store has been created, we simply call the store’s “add” method with a config object that represents the data, then calling sync() on that store forces an insert (or create) to be executed through the proxy.&#160; If I look at Chrome’s JavaScript debugger (network tab), you can see from the picture below that indeed, the servers UserInfo/Create method has been called passing in the parameters Name and Email.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image14.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image_thumb12.png" width="516" height="192" /></a></p>
<p>&#160;</p>
<p>It’s important to understand these steps because we will be using the store and model in a similar way when we update the data in our next section.</p>
<p>&#160;</p>
<h2>Implementation in Grid and Editor Panel</h2>
<p>&#160;</p>
<p>We are using the ExtJS MVC architecture for this app so all our procedural code is in the controller.&#160; For the Ext.grid.Panel, all we have for the view is the following (app/view/List.js).</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image15.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/04/image_thumb13.png" width="322" height="179" /></a></p>
<p>&#160;</p>
<pre class="csharpcode">Ext.define(<span class="str">'AM.view.user.List'</span>, {
    extend: <span class="str">'Ext.grid.Panel'</span>,
    alias: <span class="str">'widget.userlist'</span>,

    title: <span class="str">'All Users'</span>,
    store: <span class="str">'Users'</span>,

    columns: [
    { header: <span class="str">'Name'</span>, dataIndex: <span class="str">'Name'</span>, flex: 1 },
    { header: <span class="str">'Email'</span>, dataIndex: <span class="str">'Email'</span>, flex: 1 }
    ]
});</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Then, in our controller (app/controller/Users.js) we have the working code that actually does the editing and updating of the record.&#160; the code is below:</p>
<pre class="csharpcode">Ext.define(<span class="str">'AM.controller.Users'</span>, {
    extend: <span class="str">'Ext.app.Controller'</span>,
    stores: [<span class="str">'Users'</span>],
    models: [<span class="str">'User'</span>],
    views: [<span class="str">'user.Edit'</span>, <span class="str">'user.List'</span>],
    refs: [
        {
            <span class="kwrd">ref</span>: <span class="str">'usersPanel'</span>,
            selector: <span class="str">'panel'</span>
        }
    ],
    init: <span class="kwrd">function</span>() {
        <span class="kwrd">this</span>.control({
            <span class="str">'viewport &gt; userlist dataview'</span>: {
                itemdblclick: <span class="kwrd">this</span>.editUser
            },
            <span class="str">'useredit button[action=save]'</span>: {
                click: <span class="kwrd">this</span>.updateUser
            }
        });
    },
    editUser: <span class="kwrd">function</span>(grid, record) {
        <span class="kwrd">var</span> edit = Ext.create(<span class="str">'AM.view.user.Edit'</span>).show();

        edit.down(<span class="str">'form'</span>).loadRecord(record);
    },
    updateUser: <span class="kwrd">function</span>(button) {
        <span class="kwrd">var</span> win    = button.up(<span class="str">'window'</span>),
            form   = win.down(<span class="str">'form'</span>),
            record = form.getRecord(),
            values = form.getValues();
        record.set(values);
        win.close();
        <span class="kwrd">this</span>.getUsersStore().sync();
    }
});</pre>
<p>Basically, this follows the exact same method we described above for implementing the CRUD.&#160; Note getUsersStore().sync.&#160; This does the same thing as shown above to force the appropriate call the back end.</p>
<p>&#160;</p>
<h2>Remarks</h2>
<p>Hope this helps give you a little more understanding into updating with the ExtJS library. If you are looking for the source, it’s in part 1 of this series.</p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/04/20/details-on-the-extjs-application-to-build-simple-crud-operation-using-models-and-stores/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>EntityFramework 4.3 CodeFirst Trivial One File Example &#8211; Part 1</title>
		<link>http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=entityframework-4-3-codefirst-trivial-one-file-example-part-1</link>
		<comments>http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 18:47:26 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=1841</guid>
		<description><![CDATA[&#160;
Introduction
This three part series demonstrates a very simple example of using Entity Framework Code First (Version 4.3) to create a SqlServer Table and populate it with data (that is part 1).&#160; Part 2 adds two new columns to the table a populates the data conditionally (while migrating from a non migration enabled project), and Part [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h2>Introduction</h2>
<p>This three part series demonstrates a very simple example of using <a href="http://www.asp.net/entity-framework">Entity Framework</a> <a href="http://msdn.microsoft.com/en-us/data/aa937723">Code First</a> (<a href="http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-released.aspx">Version 4.3</a>) to create a <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">SqlServer</a> Table and populate it with data (that is part 1).&#160; Part 2 adds two new columns to the table a populates the data conditionally (while migrating from a non migration enabled project), and Part 3 adds a new column with a default value to a migration enabled code first project.</p>
<p>As it happens, I watched President Obama drive by me in San Francisco yesterday so he will be the star of the post.&#160; The table we will use is called Presidents, and the columns we will add are Year Elected and Current.&#160; We will obviously only have one current president so we will have to have our migration conditionally set CurrentPresident to true for Obama.</p>
<p>&#160;</p>
<p>&#160;</p>
<div>
<div style="float: right">
<p align="center"><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb4_thumb2.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image_thumb4_thumb2" border="0" alt="image_thumb4_thumb2" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb4_thumb2_thumb.png" width="244" height="176" /></a>         <br /><em>I need practice with my cell phone camera (obviously)</em>&#160; </p>
</p></div>
<div>
<table border="1" cellspacing="0" cellpadding="2" width="360">
<tbody>
<tr>
<td valign="top" width="224"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1">Part 1</a></strong></td>
<td valign="top" width="234"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1">Building a 1 File Console App That Creates a SqlServer Table and Populates it With Data</a></strong></td>
</tr>
<tr>
<td valign="top" width="243"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-codefirst-4-3-adding-data-migration-to-simple-example-part-2">Part 2</a></strong></td>
<td valign="top" width="244"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-codefirst-4-3-adding-data-migration-to-simple-example-part-2">Adding Two New Columns To the Customer Table and Populating Data Conditionally using New Migrations Feature (With Upgrade To Code Migrations from Project Without Code Migrations)</a></strong></td>
</tr>
<tr>
<td valign="top" width="243"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-code-first-4-3-adding-a-single-default-column-to-a-migration-enabled-project-part-3">Part 3</a></strong></td>
<td valign="top" width="244"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-code-first-4-3-adding-a-single-default-column-to-a-migration-enabled-project-part-3">Changing your CodeFirst DataModel with Migrations Enabled</a></strong></td>
</tr>
</tbody>
</table></div>
<div>&#160;</div>
<div>For those wanting the real code, the final visual studio solution after part 3, includes parts 1 and 2 information is here:&#160;
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:1592ae0a-feab-473c-a58f-1002482b399d" class="wlWriterSmartContent">
<p><a href="file:///C:/Users/pkellner/AppData/Local/Temp/WindowsLiveWriter1286139640/supfiles11F36BE/ConApp[2].zip" target="_blank">VS Solution</a></p>
</p></div>
</p></div>
</p></div>
<div>&#160;</div>
<div>&#160;</div>
<h2>
<p>&#160;</p>
<p>What To Do</p>
</h2>
<div>We simply create a console version with Visual Studio 2010 in c#.&#160; Using nuget package manager console we say “Install-Package EntityFramework”, then replace the primary Program.cs with the following file (you should add a connection string with the name SiteDB also if you want it to create a SqlServer Database.</div>
<div>&#160;</div>
<div>Here is the code:</div>
<div>&#160;</div>
<pre class="csharpcode"><span class="kwrd">namespace</span> ConApp
{
    <span class="kwrd">internal</span> <span class="kwrd">class</span> Program
    {
        <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> Main()
        {
            Database.SetInitializer&lt;SiteDB&gt;(<span class="kwrd">new</span> SiteDBInitialize());
            <span class="kwrd">using</span> (var myContext = <span class="kwrd">new</span> SiteDB())
            {
                var x = myContext.Presidents.ToList();
            }
        }
    }

    <span class="kwrd">public</span> <span class="kwrd">class</span> SiteDB : DbContext
    {
        <span class="kwrd">public</span> DbSet&lt;Presidents&gt; Presidents { get; set; }
    }

    <span class="kwrd">public</span> <span class="kwrd">class</span> Presidents
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">string</span> LastName { get; set; }
    }

    <span class="kwrd">public</span> <span class="kwrd">class</span> SiteDBInitialize :
        DropCreateDatabaseIfModelChanges&lt;SiteDB&gt;
    {
        <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Seed(SiteDB context)
        {
            context.Presidents.Add(<span class="kwrd">new</span> Presidents { LastName = <span class="str">&quot;Reagan&quot;</span> });
            context.Presidents.Add(<span class="kwrd">new</span> Presidents { LastName = <span class="str">&quot;Bush&quot;</span> });
            context.Presidents.Add(<span class="kwrd">new</span> Presidents { LastName = <span class="str">&quot;Obama&quot;</span> });
            context.SaveChanges();
        }
    }

}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>I won’t go into details of all the steps because this is all very well documented on the EF site at this url among others:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/gg696189(v=vs.103).aspx">http://msdn.microsoft.com/en-us/library/gg696189(v=vs.103).aspx</a></p>
<p>What is interesting to note is that I am implementing the interface DropCreateDatabaseIfModelChanges.&#160; What stumped me for a while was that in my main console, we always call new SiteDBInitialize), however what that class implments determines the action on creation.&#160; There are three choices.</p>
<ol>
<li><a href="http://msdn.microsoft.com/en-us/library/gg679604(v=vs.103).aspx">DropCreateDatabaseIfModelChanges</a> </li>
<li><a href="http://msdn.microsoft.com/en-us/library/gg679506(v=vs.103).aspx">DropCreateDatabaseAlways</a> </li>
<li><a href="http://msdn.microsoft.com/en-us/library/gg679221(v=vs.103).aspx">CreateDatabaseIfNotExists</a> </li>
</ol>
<p>The meaning is self explanatory, you just need to derive from the appropriate class depending on what your intention is.&#160; All the calls can be seen here in the MSDN documentation:&#160; <a href="http://msdn.microsoft.com/en-us/library/gg696142(v=vs.103).aspx">http://msdn.microsoft.com/en-us/library/gg696142(v=vs.103).aspx</a></p>
<p>Hope this helps, read on to part 2 to find out how to add some columns and conditionally populate them.</p>
<p>&#160;</p>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>EntityFramework Code First 4.3, Adding a Single Default Column to a Migration Enabled Project, Part 3</title>
		<link>http://peterkellner.net/2012/02/17/entityframework-code-first-4-3-adding-a-single-default-column-to-a-migration-enabled-project-part-3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=entityframework-code-first-4-3-adding-a-single-default-column-to-a-migration-enabled-project-part-3</link>
		<comments>http://peterkellner.net/2012/02/17/entityframework-code-first-4-3-adding-a-single-default-column-to-a-migration-enabled-project-part-3/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 18:46:04 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=1838</guid>
		<description><![CDATA[&#160;
Introduction
This three part series demonstrates a very simple example of using Entity Framework Code First (Version 4.3) to create a SqlServer Table and populate it with data (that is part 1).&#160; Part 2 adds two new columns to the table a populates the data conditionally (while migrating from a non migration enabled project), and Part [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h2>Introduction</h2>
<p>This three part series demonstrates a very simple example of using <a href="http://www.asp.net/entity-framework">Entity Framework</a> <a href="http://msdn.microsoft.com/en-us/data/aa937723">Code First</a> (<a href="http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-released.aspx">Version 4.3</a>) to create a <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">SqlServer</a> Table and populate it with data (that is part 1).&#160; Part 2 adds two new columns to the table a populates the data conditionally (while migrating from a non migration enabled project), and Part 3 adds a new column with a default value to a migration enabled code first project.</p>
<p>As it happens, I watched President Obama drive by me in San Francisco yesterday so he will be the star of the post.&#160; The table we will use is called Presidents, and the columns we will add are Year Elected and Current.&#160; We will obviously only have one current president so we will have to have our migration conditionally set CurrentPresident to true for Obama.</p>
<p>&#160;</p>
<p>&#160;</p>
<div>
<div style="float: right">
<p align="center"><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb4_thumb21.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image_thumb4_thumb2" border="0" alt="image_thumb4_thumb2" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb4_thumb2_thumb1.png" width="244" height="176" /></a>         <br /><em>I need practice with my cell phone camera (obviously)</em>&#160; </p>
</p></div>
<div>
<table border="1" cellspacing="0" cellpadding="2" width="360">
<tbody>
<tr>
<td valign="top" width="224"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1">Part 1</a></strong></td>
<td valign="top" width="234"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1">Building a 1 File Console App That Creates a SqlServer Table and Populates it With Data</a></strong></td>
</tr>
<tr>
<td valign="top" width="243"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-codefirst-4-3-adding-data-migration-to-simple-example-part-2">Part 2</a></strong></td>
<td valign="top" width="244"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-codefirst-4-3-adding-data-migration-to-simple-example-part-2">Adding Two New Columns To the Customer Table and Populating Data Conditionally using New Migrations Feature (With Upgrade To Code Migrations from Project Without Code Migrations)</a></strong></td>
</tr>
<tr>
<td valign="top" width="243"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-code-first-4-3-adding-a-single-default-column-to-a-migration-enabled-project-part-3">Part 3</a></strong></td>
<td valign="top" width="244"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-code-first-4-3-adding-a-single-default-column-to-a-migration-enabled-project-part-3">Changing your CodeFirst DataModel with Migrations Enabled</a></strong></td>
</tr>
</tbody>
</table></div>
<div>&#160;</div>
<div>For those wanting the real code, the final visual studio solution after part 3, includes parts 1 and 2 information is here:&#160;
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:1592ae0a-feab-473c-a58f-1002482b399d" class="wlWriterSmartContent">
<p><a href="file:///C:/Users/pkellner/AppData/Local/Temp/WindowsLiveWriter1286139640/supfiles11F36BE/ConApp[2].zip" target="_blank">VS Solution</a></p>
</p></div>
</p></div>
</p></div>
<div>&#160;</div>
<div>&#160;</div>
<h2>Goal</h2>
<p>In this post, we will show the steps necessary to add a single column (Party) to the Presidents table.&#160; Because in Part 2 we enabled Code Migrations, this will be a lot simpler than in Part 2.&#160; </p>
<p>&#160;</p>
<h2>Let’s Do it!</h2>
<p>Now, we have a stable project that is running correctly with the database table Presidents defined as follows:</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image12.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb11.png" width="390" height="121" /></a></p>
<p>We want to add a new column “Party” so let’s update the model file (it’s in our original programs.cs file).&#160; It will now be changed as follows:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Presidents
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }
    <span class="kwrd">public</span> <span class="kwrd">string</span> LastName { get; set; }

    <span class="rem">// New Columns for first migration</span>
    <span class="kwrd">public</span> <span class="kwrd">int</span> YearElected { get; set; }
    <span class="kwrd">public</span> <span class="kwrd">bool</span> CurrentPresident { get; set; }

    <span class="rem">// New Column for second migration</span>
    <span class="kwrd">public</span> <span class="kwrd">string</span> Party { get; set; }
}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>We now have to create the .cs files in the MIgration folder that will know about this change.&#160; So, we simply execute the command from the package manager Add-Migration AddNewColumnParty and we get the following results:</p>
<blockquote>
<p>PM&gt; Add-Migration AddNewColumnParty<br />
    <br />Scaffolding migration &#8216;AddNewColumnParty&#8217;. </p>
<p>The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running &#8216;Add-Migration 201202171832107_AddNewColumnParty&#8217; again.</p>
</blockquote>
<p>Now, we want to add some customization because we know that Bush and Reagan are republicans and Obama is a democrat.&#160; So, we add to the “Up()” method the following:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Up()
{
    AddColumn(<span class="str">&quot;Presidents&quot;</span>, <span class="str">&quot;Party&quot;</span>, c =&gt; c.String());

    Sql(<span class="str">&quot;UPDATE Presidents SET Party = 'Republican' WHERE LastName='ReaganX'&quot;</span>);
    Sql(<span class="str">&quot;UPDATE Presidents SET Party = 'Republican' WHERE LastName='BushX'&quot;</span>);
    Sql(<span class="str">&quot;UPDATE Presidents SET Party = 'Democrat' WHERE LastName='ObamaX'&quot;</span>);
}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Now, we run the package manager command: Update-Database –Verbose and the work is done for us.</p>
<blockquote>
<p>PM&gt; Update-Database -Verbose<br />
    <br />Using NuGet project &#8216;ConApp&#8217;. </p>
<p>Using StartUp project &#8216;ConApp&#8217;. </p>
<p>Target database is: &#8216;agelessemail&#8217; (DataSource: ., Provider: System.Data.SqlClient, Origin: Configuration). </p>
<p>Applying explicit migrations: [201202171832107_AddNewColumnParty]. </p>
<p>Applying explicit migration: 201202171832107_AddNewColumnParty. </p>
<p>ALTER TABLE [Presidents] ADD [Party] [nvarchar](max) </p>
<p>UPDATE Presidents SET Party = &#8216;Republican&#8217; WHERE LastName=&#8217;ReaganX&#8217; </p>
<p>UPDATE Presidents SET Party = &#8216;Republican&#8217; WHERE LastName=&#8217;BushX&#8217; </p>
<p>UPDATE Presidents SET Party = &#8216;Democrat&#8217; WHERE LastName=&#8217;ObamaX&#8217; </p>
<p>[Inserting migration history record]</p>
</blockquote>
<p>Now, looking at the generated data we have:</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image13.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb12.png" width="375" height="149" /></a></p>
<p>&#160;</p>
<p>Keep in mind that “Update-Database” figured out what database we were on and just did the appropriate update.&#160; The beauty of this is if some developer in the group is on a different version, all she has to do is say “Update-Database” and there database will be brought up to date along with whatever version was current at the time.</p>
<p>&#160;</p>
<h2>Conclusions</h2>
<p>All I can say is <strong>“Congrats!”</strong> to the Microsoft engineers.&#160; I’ve been doing ORM’s for a long time and have my doubts along the way about some Microsoft has rolled out, but this time, I think they really have listened and done what we need.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/02/17/entityframework-code-first-4-3-adding-a-single-default-column-to-a-migration-enabled-project-part-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>EntityFramework CodeFirst 4.3, Adding Data Migration To Simple Example (Part 2)</title>
		<link>http://peterkellner.net/2012/02/17/entityframework-codefirst-4-3-adding-data-migration-to-simple-example-part-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=entityframework-codefirst-4-3-adding-data-migration-to-simple-example-part-2</link>
		<comments>http://peterkellner.net/2012/02/17/entityframework-codefirst-4-3-adding-data-migration-to-simple-example-part-2/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 18:41:25 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=1832</guid>
		<description><![CDATA[&#160;
Introduction
This three part series demonstrates a very simple example of using Entity Framework Code First (Version 4.3) to create a SqlServer Table and populate it with data (that is part 1).&#160; Part 2 adds two new columns to the table a populates the data conditionally (while migrating from a non migration enabled project), and Part [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h2>Introduction</h2>
<p>This three part series demonstrates a very simple example of using <a href="http://www.asp.net/entity-framework">Entity Framework</a> <a href="http://msdn.microsoft.com/en-us/data/aa937723">Code First</a> (<a href="http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-released.aspx">Version 4.3</a>) to create a <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">SqlServer</a> Table and populate it with data (that is part 1).&#160; Part 2 adds two new columns to the table a populates the data conditionally (while migrating from a non migration enabled project), and Part 3 adds a new column with a default value to a migration enabled code first project.</p>
<p>As it happens, I watched President Obama drive by me in San Francisco yesterday so he will be the star of the post.&#160; The table we will use is called Presidents, and the columns we will add are Year Elected and Current.&#160; We will obviously only have one current president so we will have to have our migration conditionally set CurrentPresident to true for Obama.</p>
<p>&#160;</p>
<p>&#160;</p>
<div>
<div style="float: right">
<p align="center"><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb41.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image_thumb4" border="0" alt="image_thumb4" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb4_thumb.png" width="272" height="195" /></a>         <br /><em>I need practice with my cell phone camera (obviously)</em>&#160; </p>
</p></div>
<div>
<table border="1" cellspacing="0" cellpadding="2" width="360">
<tbody>
<tr>
<td valign="top" width="224"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1">Part 1</a></strong></td>
<td valign="top" width="234"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-4-3-codefirst-trivial-one-file-example-part-1">Building a 1 File Console App That Creates a SqlServer Table and Populates it With Data</a></strong></td>
</tr>
<tr>
<td valign="top" width="243"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-codefirst-4-3-adding-data-migration-to-simple-example-part-2">Part 2</a></strong></td>
<td valign="top" width="244"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-codefirst-4-3-adding-data-migration-to-simple-example-part-2">Adding Two New Columns To the Customer Table and Populating Data Conditionally using New Migrations Feature (With Upgrade To Code Migrations from Project Without Code Migrations)</a></strong></td>
</tr>
<tr>
<td valign="top" width="243"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-code-first-4-3-adding-a-single-default-column-to-a-migration-enabled-project-part-3">Part 3</a></strong></td>
<td valign="top" width="244"><strong><a href="http://peterkellner.net/2012/02/17/entityframework-code-first-4-3-adding-a-single-default-column-to-a-migration-enabled-project-part-3">Changing your CodeFirst DataModel with Migrations Enabled</a></strong></td>
</tr>
</tbody>
</table></div>
<div>&#160;</div>
<div>For those wanting the real code, the final visual studio solution after part 3, includes parts 1 and 2 information is here:&#160;
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:1592ae0a-feab-473c-a58f-1002482b399d" class="wlWriterEditableSmartContent">
<p> <a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/ConApp.zip" target="_blank">VS Solution</a></p>
</div>
</div></div>
<div>&#160;</div>
<div>&#160;</div>
<h2>Our Goal</h2>
<div>&#160;</div>
<div>We simply want to update the table “Presidents” which currently has two columns, Id and LastName.&#160; We want to add the columns “YearElected” and “Current”.&#160; If the president (LastName) is Obama, we want to set CurrentPresident to true, if not false.</div>
<div>&#160;</div>
<div>&#160;</div>
<div><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image6.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb6.png" width="244" height="108" /></a></div>
<div>&#160;</div>
<h2>Here We Go</h2>
<div>&#160;</div>
<div>First thing, let’s make sure that our SiteDBInitialize (see part 1) is set to implement CreateDatabaseIfNotExists.&#160; That code should look like the following:</div>
<div>&#160;</div>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> SiteDBInitialize :
        CreateDatabaseIfNotExists&lt;SiteDB&gt;
    {</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<div>&#160;</div>
<div>Next, let’s add the columns to both our Seed method as well as the Presidents class.&#160; For clarity, I’m pasting the complete program below (remember, this is it!)</div>
<div>&#160;</div>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.ComponentModel.DataAnnotations;
<span class="kwrd">using</span> System.Linq;
<span class="kwrd">using</span> System.Text;
<span class="kwrd">using</span> System.Data.Entity;

<span class="kwrd">namespace</span> ConApp
{
    <span class="kwrd">internal</span> <span class="kwrd">class</span> Program
    {
        <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> Main()
        {
            Database.SetInitializer&lt;SiteDB&gt;(<span class="kwrd">new</span> SiteDBInitialize());
            <span class="kwrd">using</span> (var myContext = <span class="kwrd">new</span> SiteDB())
            {
                var x = myContext.Presidents.ToList();
            }
        }
    }

    <span class="kwrd">public</span> <span class="kwrd">class</span> SiteDB : DbContext
    {
        <span class="kwrd">public</span> DbSet&lt;Presidents&gt; Presidents { get; set; }
    }

    <span class="kwrd">public</span> <span class="kwrd">class</span> Presidents
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        <span class="kwrd">public</span> <span class="kwrd">long</span> Id { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">string</span> LastName { get; set; }

        <span class="rem">// New Columns:</span>
        <span class="kwrd">public</span> <span class="kwrd">int</span> YearElected { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">bool</span> CurrentPresident { get; set; }
    }

    <span class="kwrd">public</span> <span class="kwrd">class</span> SiteDBInitialize :
        CreateDatabaseIfNotExists&lt;SiteDB&gt;
    {
        <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Seed(SiteDB context)
        {
            context.Presidents.Add(<span class="kwrd">new</span> Presidents
                                       {
                                           LastName = <span class="str">&quot;Reagan&quot;</span>,
                                           CurrentPresident = <span class="kwrd">false</span>,
                                           YearElected = 1984
                                       });
            context.Presidents.Add(<span class="kwrd">new</span> Presidents
                                       {
                                           LastName = <span class="str">&quot;Bush&quot;</span>,
                                           CurrentPresident = <span class="kwrd">false</span>,
                                           YearElected = 1992
                                       });
            context.Presidents.Add(<span class="kwrd">new</span> Presidents
                                       {
                                           LastName = <span class="str">&quot;Obama&quot;</span>,
                                           CurrentPresident = <span class="kwrd">true</span>,
                                           YearElected = 2008
                                       });
            context.SaveChanges();
        }
    }

}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>In our case, the initializer will only be called if the database does not exist.&#160; Let’s change the data in the database just so we know that our data has been migrated and not simply replaced.&#160; Here is a screen shot of what I’ve changed it to (notice I’ve added an “x” to the end of each LastName).</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image7.png"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb7.png" width="205" height="149" /></a></p>
<p>&#160;</p>
<p>Now, if I run this, I get an error that says I need to run migrations.&#160; The error is as follows:</p>
<blockquote>
<p>Unhandled Exception: System.InvalidOperationException: The model backing the &#8216;Si<br />
    <br />teDB&#8217; context has changed since the database was created. Consider using Code Fi </p>
<p>rst Migrations to update the database (<a href="http://go.microsoft.com/fwlink/?LinkId=23">http://go.microsoft.com/fwlink/?LinkId=23</a> </p>
<p>8269). </p>
<p>&#160;&#160; at System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext </p>
<p>context)</p>
</blockquote>
<p>This is great!&#160; It is telling me my model has changed and telling me where I need to go look to learn what to do.&#160; So, after looking there, I discover (with a little digging) that I need to –EnableAutomatic.</p>
<p>&#160;</p>
<p><a href="http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image8.png" width="433" height="70" /></a></p>
<p>&#160;</p>
<p>After doing this, I’m surprised to get this error (OK, I admit I’m learning this new feature, it just came out this week) as I’m writing this blog post.</p>
<blockquote>
<p>PM&gt; Enable-Migrations<br />
    <br />Detected database created with a database initializer. Scaffolded migration &#8217;201202171606443_InitialCreate&#8217; corresponding to current database schema. To use an automatic migration instead, delete the Migrations folder and re-run Enable-Migrations specifying the -EnableAutomaticMigrations parameter. </p>
<p>Code First Migrations enabled for project ConApp.</p>
</blockquote>
<p>What I see happened is that Enable-Migrations create a new folder structure as follows:</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image9.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb8.png" width="244" height="188" /></a></p>
<p>&#160;</p>
<p>Basically, what has happened is “Enable-Migrations” did the following:</p>
<ol>
<li>Create a file Migrations/Configuration (determines how migrations behave for the current context, one in this case, DBSite). </li>
<li>201..443_InitialCreate.cs was created because our initial database was created before migrations were enabled.&#160; It represents just the table before the latest columns were added. </li>
</ol>
<p>Now, we run the package manager commanda:&#160; </p>
<blockquote>
<p><em>Add-Migration AddingNewColumnsElectedYearAndCurrentPresident</em></p>
</blockquote>
<p>And, from that we get the message:</p>
<blockquote>
<p>The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running &#8216;Add-Migration 201202171748276_AddingNewColumnsElectedYearAndCurrentPresident&#8217; again.</p>
</blockquote>
<p>Now, we have some new files in our Migrations folder as follows:</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image10.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb9.png" width="459" height="108" /></a></p>
<p>This file: 201202171748276_AddingNewColumnsElectedYearAndCurrentPresident.cs has code in it that both upgrades and downgrades our database.&#160; Very nice Microsoft!</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> AddingNewColumnsElectedYearAndCurrentPresident : DbMigration
    {
        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Up()
        {
            AddColumn(<span class="str">&quot;Presidents&quot;</span>, <span class="str">&quot;YearElected&quot;</span>, c =&gt; c.Int(nullable: <span class="kwrd">false</span>));
            AddColumn(<span class="str">&quot;Presidents&quot;</span>, <span class="str">&quot;CurrentPresident&quot;</span>, c =&gt; c.Boolean(nullable: <span class="kwrd">false</span>));
        }

        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Down()
        {
            DropColumn(<span class="str">&quot;Presidents&quot;</span>, <span class="str">&quot;CurrentPresident&quot;</span>);
            DropColumn(<span class="str">&quot;Presidents&quot;</span>, <span class="str">&quot;YearElected&quot;</span>);
        }
    }</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Then, to the Up method, let’s add our custom datacolumn settings:</p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Up()
{
    AddColumn(<span class="str">&quot;Presidents&quot;</span>, <span class="str">&quot;YearElected&quot;</span>, c =&gt; c.Int(nullable: <span class="kwrd">false</span>));
    AddColumn(<span class="str">&quot;Presidents&quot;</span>, <span class="str">&quot;CurrentPresident&quot;</span>, c =&gt; c.Boolean(nullable: <span class="kwrd">false</span>));

    Sql(<span class="str">&quot;UPDATE Presidents SET CurrentPresident = 0,YearElected = 1980 WHERE LastName='ReaganX'&quot;</span>);
    Sql(<span class="str">&quot;UPDATE Presidents SET CurrentPresident = 1,YearElected = 1992 WHERE LastName='BushX'&quot;</span>);
    Sql(<span class="str">&quot;UPDATE Presidents SET CurrentPresident = 1,YearElected = 2008 WHERE LastName='ObamaX'&quot;</span>);
}</pre>
<p>Not forgetting, we need to enable automatic migrations as follows in the Configuration.cs file</p>
<pre class="csharpcode"><span class="kwrd">internal</span> <span class="kwrd">sealed</span> <span class="kwrd">class</span> Configuration : DbMigrationsConfiguration&lt;ConApp.SiteDB&gt;
    {
        <span class="kwrd">public</span> Configuration()
        {
            AutomaticMigrationsEnabled = <span class="kwrd">true</span>;
        }</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>&#160;</p>
<p>Now, Build your app (probably necessary) and run the update database package command: </p>
<blockquote>
<p>PM&gt; Update-Database -Verbose</p>
</blockquote>
<p>And you’ll get this nice output showing you the sql generated:</p>
<blockquote>
<p>Using NuGet project &#8216;ConApp&#8217;.<br />
    <br />Using StartUp project &#8216;ConApp&#8217;. </p>
<p>Target database is: &#8216;agelessemail&#8217; (DataSource: ., Provider: System.Data.SqlClient, Origin: Configuration). </p>
<p>Applying explicit migrations: [201202171748276_AddingNewColumnsElectedYearAndCurrentPresident]. </p>
<p>Applying explicit migration: 201202171748276_AddingNewColumnsElectedYearAndCurrentPresident. </p>
<p>ALTER TABLE [Presidents] ADD [YearElected] [int] NOT NULL DEFAULT 0 </p>
<p>ALTER TABLE [Presidents] ADD [CurrentPresident] [bit] NOT NULL DEFAULT 0 </p>
<p>UPDATE Presidents SET CurrentPresident = 0,YearElected = 1980 WHERE LastName=&#8217;ReaganX&#8217; </p>
<p>UPDATE Presidents SET CurrentPresident = 1,YearElected = 1992 WHERE LastName=&#8217;Bush&#8217; </p>
<p>UPDATE Presidents SET CurrentPresident = 1,YearElected = 2008 WHERE LastName=&#8217;ObamaX&#8217; </p>
<p>[Inserting migration history record]</p>
</blockquote>
<p>And when you look at the data, you will of course see:</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image11.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2012/02/image_thumb10.png" width="483" height="150" /></a></p>
<p>&#160;</p>
<h2>Conclusions</h2>
<p>OK, this was a little more involved than I thought it would be.&#160; Primarily because we were going from a project that did not have code migrations enabled to one that does (I am glad I went through the exercise though).&#160; In Part 3 (which I was not planning on doing) I’ll look at what it takes to add YAC (yet another column) to the Presidents Table now that we have Automatic Code Migrations enabled.</p>
<p>Hope this helps!&#160; Move on to part 3 now.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/02/17/entityframework-codefirst-4-3-adding-data-migration-to-simple-example-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MACBook PRO running VMWARE Fusion with Visual Studio</title>
		<link>http://peterkellner.net/2012/02/07/macbook-pro-running-vmware-fusion-with-visual-studio/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=macbook-pro-running-vmware-fusion-with-visual-studio</link>
		<comments>http://peterkellner.net/2012/02/07/macbook-pro-running-vmware-fusion-with-visual-studio/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 20:59:28 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/02/07/macbook-pro-running-vmware-fusion-with-visual-studio/</guid>
		<description><![CDATA[I’ve been a macbook user for about 2 weeks now.&#160; As a Microsoft guy, it’s really important to me that the Macbook run Windows 7 really well.&#160; So far, I’m not impressed (hopefully this will change once you all give me some good advice).&#160; I’ve set up bootcamp on half my SSD drive and OSX [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been a macbook user for about 2 weeks now.&#160; As a Microsoft guy, it’s really important to me that the Macbook run Windows 7 really well.&#160; So far, I’m not impressed (hopefully this will change once you all give me some good advice).&#160; I’ve set up bootcamp on half my SSD drive and OSX Lion on the other half.&#160; VMWare seems to run reasonably well, but when I try and run Visual Studio I get lots of hanging and very very slow performance.&#160; I’ve got 16Gig of RAM and the latest macbook with a core i7.&#160; I’ve tried giving VMWARE 4 or 8 GB’s of ram, but have the same issues.</p>
<p>I’ve also run bootcamp native and had some hanging also, but not as bad as Fusion.</p>
<p>Anyone else have similar experiences?&#160; Any suggestions?&#160; I’ve heard that macbook’s are awesome at running windows 7.&#160; So far, I have not experience that.&#160; </p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/02/07/macbook-pro-running-vmware-fusion-with-visual-studio/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Take Defaults! (not customizations) When Installing Software</title>
		<link>http://peterkellner.net/2012/01/31/take-defaults-not-customizations-when-installing-software/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=take-defaults-not-customizations-when-installing-software</link>
		<comments>http://peterkellner.net/2012/01/31/take-defaults-not-customizations-when-installing-software/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 05:55:11 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/01/31/take-defaults-not-customizations-when-installing-software/</guid>
		<description><![CDATA[&#160;
Some Background
Years ago, my friend Bill Venners of Artima told me a life long lesson that I always seem to forget.&#160; He said that when people design installation programs, they always thoroughly test the “default” installation but not all the corner cases around custom options.
Today, while configuring my new MacBook (Best Windows 7 Computer Laptop [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<h2>Some Background</h2>
<p>Years ago, my friend Bill Venners of <a href="http://www.artima.com/weblogs/index.jsp?blogger=bv">Artima</a> told me a life long lesson that I always seem to forget.&#160; He said that when people design <a href="http://www.apple.com/macosx/recovery/">installation</a> programs, they always thoroughly test the “default” installation but not all the corner cases around custom options.</p>
<p>Today, while configuring my new <a href="http://www.apple.com/mac/">MacBook</a> (Best <a href="http://windows.microsoft.com/en-us/windows7/products/home">Windows 7</a> Computer Laptop they say), I learned this lesson all over again.&#160; So, here is the story.</p>
<p>&#160;</p>
<h2>
<p>How To Split Your Hard MacBook Primary Drive 50/50, IOS Lion and Windows 7</p>
</h2>
<p>My thinking is that I need to first allocate a NTFS partition on the MacBook that takes half my hard drive and let the OSX Lion install take over the rest.&#160; After about 10 iterations of IOS complaining that it did not have enough resources, I finally decided to take a step backwards and ask myself “how would my mom be able to do this?” and we all know that Mac’s are designed for my mom.&#160; So, with that thinking, I just let the IOS Lion install take over the entire disk.&#160; Then I ran the Boot Camp Assistant.&#160; It asked me how much of my hard drive I wanted for Windows, I said 50% and everything ran perfect.&#160; No partition magic, no special setup, just take the defaults with <a href="http://www.apple.com/support/bootcamp/">bootcamp</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/01/31/take-defaults-not-customizations-when-installing-software/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PC verses MAC (let the debate continue)</title>
		<link>http://peterkellner.net/2012/01/24/pc-verses-mac-let-the-debate-continue/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pc-verses-mac-let-the-debate-continue</link>
		<comments>http://peterkellner.net/2012/01/24/pc-verses-mac-let-the-debate-continue/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 19:14:37 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2012/01/24/pc-verses-mac-let-the-debate-continue/</guid>
		<description><![CDATA[&#160;
So, I know it’s hard to believe, but I am actually considering getting a Macbook to use as my main development computer.&#160; The reason is I’m using some beta mobile development tools that only support the Mac.&#160; The problem is that if I don’t use these tools and incrementally build my app with them, I [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>So, I know it’s hard to believe, but I am actually considering getting a Macbook to use as my main development computer.&#160; The reason is I’m using some beta mobile development tools that only support the Mac.&#160; The problem is that if I don’t use these tools and incrementally build my app with them, I will get my app far out of wac (wac being a technical term) that I will never be able to get it back in wac again.&#160; </p>
<p>So, I have a good friend who is a Mac wizard and I thought I’d ask him a question.&#160; Below is my question and his answer.&#160; Keep in mind, my friend is very technical in the Mac world.</p>
<p>Question from me (PC Guy):</p>
<blockquote><p>I’ve been trying to figure that out for myself which Mac model to get.&#160; If I get one, I want SandyBridge or later.&#160; I think that’s quad core, but hard to tell.&#160; Apple just seems to give dates on the refurbished site for their computers.&#160; It’s also good to know they work with 16gb ram.&#160; I need that because I run big fat windows VM’s.&#160; The other thing I can’t quite figure out is if the 15’s support 2 drives internally if you are willing to forego the optical drive.&#160; I like to run the boot drive as SSD (SATA3) and the secondary drive as just a normal SATA2 or SATA3.</p>
</blockquote>
<p>My Friends answer (MAC Guy)</p>
<blockquote><p>You&#8217;re talking like a pc guy. Pick the prettiest one.</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2012/01/24/pc-verses-mac-let-the-debate-continue/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Testing Help From the Twitter Sphere, Anyone have an IPad1 Handy?</title>
		<link>http://peterkellner.net/2011/12/22/testing-help-from-the-twitter-sphere-anyone-have-an-ipad1-handy/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=testing-help-from-the-twitter-sphere-anyone-have-an-ipad1-handy</link>
		<comments>http://peterkellner.net/2011/12/22/testing-help-from-the-twitter-sphere-anyone-have-an-ipad1-handy/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 01:13:09 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/12/22/testing-help-from-the-twitter-sphere-anyone-have-an-ipad1-handy/</guid>
		<description><![CDATA[I’ve been working on an HTML5/CSS3 SenchaTouch project for many months now and near the end we our finding that we have problems on an IPad1 only and all I have is an IPad2.
My 700+ twitter buddies to the rescue.
I tweet:&#160; 

And, within about 5 minutes comes back:
&#160;

&#160;
Not to mention from Facebook, another one because [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been working on an HTML5/CSS3 <a href="http://sencha.com">SenchaTouch</a> project for many months now and near the end we our finding that we have problems on an IPad1 only and all I have is an IPad2.</p>
<p>My 700+ <a href="http://twitter.com">twitter</a> buddies to the rescue.</p>
<p>I tweet:&#160; </p>
<p><a href="http://twitter.com/pkellner"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/12/image7.png" width="364" height="134" /></a></p>
<p>And, within about 5 minutes comes back:</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/12/image8.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/12/image_thumb7.png" width="368" height="369" /></a></p>
<p>&#160;</p>
<p>Not to mention from <a href="http://www.facebook.com/">Facebook</a>, another one because my tweets go to Facebook also.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/12/image9.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/12/image_thumb8.png" width="469" height="207" /></a></p>
<p>&#160;</p>
<p>At any rate, I had 3 different people testing my app on an Ipad1 within 15 minutes.</p>
<p>Totally awesome and thank you social buddies!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/12/22/testing-help-from-the-twitter-sphere-anyone-have-an-ipad1-handy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Boost Your SEO And Promote Silicon Valley Code Camp At The Same Time!</title>
		<link>http://peterkellner.net/2011/09/21/boost-your-seo-and-promote-silicon-valley-code-camp-at-the-same-time/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=boost-your-seo-and-promote-silicon-valley-code-camp-at-the-same-time</link>
		<comments>http://peterkellner.net/2011/09/21/boost-your-seo-and-promote-silicon-valley-code-camp-at-the-same-time/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 02:24:29 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=1589</guid>
		<description><![CDATA[Introduction
We have new page on the under the // ABOUT menu on the Silicon Valley Code Camp web site.  It’s called   “Live Referral Links” and essentially, it’s real time tracking of referral traffic into the code camp web site.  We normally get thousands of requests a day processed by our servers. [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>We have new page on the under the <strong><em>// ABOUT</em></strong> menu on the <a href="http://www.siliconvalley-codecamp.com/">Silicon Valley Code Camp</a> web site.  It’s called   “Live Referral Links” and essentially, it’s real time tracking of referral traffic into the code camp web site.  We normally get thousands of requests a day processed by our servers. Most of these requests come from search engines, peoples email links, stored favorites, or just typing in the url themselves.  However, if a person arrives by clicking on the Silicon Valley Code Camp link at the site <a href="http://www.json.org/">http://www.json.org/</a>, that is called a referring link and it is passed to us along with the first request to display our home page.  In the code camp program, we are now capturing those referral links, putting the in a database and storing them to be presented.</p>
<p>That’s really only half the story.  Now that we have them, we need the author of that link (like Douglas Crockford in the case of <a href="http://www.json.org">http://www.json.org</a>) to log into there code camp account, go to a special page called “My Referral Links”, find from a list of incoming url’s the ones that are his, then essentially take credit for them.  Once he has done that (as below), when any user goes to the  <strong><em>// ABOUT</em></strong> page, then selects <strong><span style="background-color: #ffffff;">Live Referral Links</span></strong> as is pointed to by the first red arrow, they will see all the referrals to code camp’s site along with how many referrals there were and the user taking credit for those links.</p>
<p>Because the Silicon Valley Code Camp web site is known by the search engines as a very reliable source of knowledge, those sites listed in the Live Referral Links page will get ranked higher and will more often be found.  Also, users may directly click on those links and return to the site.</p>
<p>This is good for everyone!  Win-Win.</p>
<p>For the Attendees who create links to our site, they get great SEO in return as described above, and for Code Camp, well, we get more traffic and attention which is what we want.  Read on for how to setup your own referral links.</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image4.png"><img title="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image_thumb3.png" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" border="0" alt="image" width="613" height="370" /></a></p>
<p><span id="more-1589"></span></p>
<h2>Getting Your Links To Show</h2>
<h3>Put a link on your Blog Post, Company Web Site, Facebook Page, etc.</h3>
<p>The first thing you need to do (if you have not done so already) is to put a link to <a href="http://www.siliconvalley-codecamp.com/">http://www.siliconvalley-codecamp.com/</a> on one of your pages.  Lots of people have done that by simply making a blog post about the event and in the post make sure you include plenty of hyperlinks to the code camp site.  No matter where on the site your link goes, you’ll get credit when someone clicks it.  That is, if you put a link directly to your sessions or track such as:  <a title="http://www.siliconvalley-codecamp.com/Sessions.aspx?track=25" href="http://www.siliconvalley-codecamp.com/Sessions.aspx?track=25">http://www.siliconvalley-codecamp.com/Sessions.aspx?track=25</a>, the person will land on the mobile track at code camp, but as far as you are concerned, you will get a “Referral Count” accumulated on your link.  For example, if you look at <a href="http://www.json.org">http://www.json.org</a> (as pictured below), you can see a Silicon Valley Code Camp link right in the middle of the page.  I just started counting referrals this morning and since then, 70 people have clicked on the link.</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image5.png"><img title="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image_thumb4.png" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" border="0" alt="image" width="299" height="272" /></a></p>
<h3>Once People Click On Your Link, Now What</h3>
<p>The Code Camp database is accumulating those links in the background waiting for someone to come and claim them.  The way to claim them is to first, make sure you are logged into your account, then go to the <strong><em>// ABOUT</em></strong> menu on the <a href="http://www.siliconvalley-codecamp.com/">Silicon Valley Code Camp</a> web site and choose the option next to <strong>Live Referral Links</strong> called <strong>My Referral Links.</strong> See the screen shot at the top of this post.  If you don’t have the My Referral links, it most likely means you are not a speaker and we will need to enable that feature on your account.  Email to <a href="mailto:service@siliconvalley-codecamp.com">service@siliconvalley-codecamp.com</a> and we will enable your account so you can chose this option (and promise us you will not be advertising your drug company online here <img src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/wlEmoticon-smile.png" style="border-style: none;" alt="Smile" class="wlEmoticon wlEmoticon-smile" />).</p>
<p>Now, you will be presented with a page that looks like this.  For the purpose of this demonstration, I’m going to log in as myself and “claim” some of the SEO I’ve been generating for code camp.  Here is the screen you should see.</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image6.png"><img title="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image_thumb5.png" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" border="0" alt="image" width="438" height="295" /></a></p>
<p>Notice that there is dropdownlist that contains all the unspoken for incoming referral links.  We are all on the honor system here so please only look for ones that belong to you.  If you drop the list down (as shown below), you’ll see the full list.  Currently, we are only showing referrals that have generated more than 3 hits, however later, we will probably up this number so the list does not get too long.</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image7.png"><img title="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image_thumb6.png" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" border="0" alt="image" width="553" height="343" /></a></p>
<p>You can see that I’ve selected my site and the count is 18.  that means, since this morning, 18 people have gone to <a href="http://peterkellner.net">http://peterkellner.net</a>, and on the right side of my blog, I have a link I generated from the Silicon Valley Code Camp “Spread The Word” page and lots of people (18) have clicked on it.  BTW, that’s a hint.  Go to that page and get a really cool chunk of HTML that you can paste into your post or page and you will have the same thing as me.  Several people actually put that right in there post about code camp.  It’s very convenient.  Just for reference, here is a picture of my <a href="http://peterkellner.net">http://peterkellner.net</a> site that includes the link to <a href="http://www.siliconvalley-codecamp.com">http://www.siliconvalley-codecamp.com</a>.</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image8.png"><img title="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image_thumb7.png" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" border="0" alt="image" width="333" height="219" /></a></p>
<p>So, once I’ve selected that from the dropdown, I see a scrren that let’s me push a button saying “Claim the Item Selected in the Above Dropdown as Your Own”.  When I press that, I now have claimed it and I’m rewared with this screen below.</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image9.png"><img title="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image_thumb8.png" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" border="0" alt="image" width="435" height="250" /></a></p>
<p>If this is all you do, you are in pretty good shape.  If you go back to the “Live Referral Links” page, you will immediately see that your link is now being tracked for the world to see.  Here is what it looks like now.</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image10.png"><img title="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image_thumb9.png" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" border="0" alt="image" width="489" height="344" /></a></p>
<p>If you wanted, you could have pressed the &#8220;<span style="text-decoration: underline;">Edit</span>” button on the previous screen and put a more descriptive name for the URL to show as well as the name of the group you posted in. For example, say this was the home page of bay.net.  You could put Bay.Net as the name of the link rather than the ugly link created by the referral.  Your credit is still the same.  Also, the last column shown is from your registration page (web site).</p>
<p>That’s it for now.  Start Posting!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/09/21/boost-your-seo-and-promote-silicon-valley-code-camp-at-the-same-time/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Silicon Valley Code Camp Login Failing with IE10 (Fixed Now)</title>
		<link>http://peterkellner.net/2011/09/20/silicon-valley-code-camp-login-failing-with-ie10-fixed-now/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=silicon-valley-code-camp-login-failing-with-ie10-fixed-now</link>
		<comments>http://peterkellner.net/2011/09/20/silicon-valley-code-camp-login-failing-with-ie10-fixed-now/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 17:10:29 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ASP.NET 4.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/09/20/silicon-valley-code-camp-login-failing-with-ie10-fixed-now/</guid>
		<description><![CDATA[&#160;
Scott Hanselman posted a while back about a browsers definition problem with some ASP.NET sites that causes problems.&#160; Microsoft has articles on this also.&#160; Having just received my BUILD tablet that includes IE10, I tested the Silicon Valley Code Camp web site and discovered that when you login, then switch to another page, the login [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p><a href="http://www.hanselman.com/blog/BugAndFixASPNETFailsToDetectIE10CausingDoPostBackIsUndefinedJavaScriptErrorOrMaintainFF5ScrollbarPosition.aspx">Scott Hanselman posted</a> a while back about a browsers definition problem with some ASP.NET sites that causes problems.&#160; Microsoft has <a href="http://support.microsoft.com/kb/2600088">articles</a> on this also.&#160; Having just received my <a href="http://www.buildwindows.com/">BUILD</a> tablet that includes IE10, I tested the <a href="http://www.siliconvalley-codecamp.com/">Silicon Valley Code Camp web site</a> and discovered that when you login, then switch to another page, the login did not stick.&#160; After uploading the two files Scott mentions (<a href="http://msdn.microsoft.com/en-us/library/ms228122.aspx">firefox.browser and ie.browser</a>), the problem goes away.</p>
<p>Thanks Scott for the heads up.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image3.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/image_thumb2.png" width="657" height="350" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/09/20/silicon-valley-code-camp-login-failing-with-ie10-fixed-now/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WinRT in Windows 8 CLR Confusion</title>
		<link>http://peterkellner.net/2011/09/15/winrt-in-windows-8-clr-confusion/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=winrt-in-windows-8-clr-confusion</link>
		<comments>http://peterkellner.net/2011/09/15/winrt-in-windows-8-clr-confusion/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 17:01:39 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/09/15/winrt-in-windows-8-clr-confusion/</guid>
		<description><![CDATA[I’m here at the Microsoft BUILD conference in Anaheim and am very much enjoying all the announcements surrouding the next major release of Windows (at least a year or two out).&#160; One of the big speculations that has drawn a lot of confusion over the past few months is whether .Net is going to part [...]]]></description>
			<content:encoded><![CDATA[<p>I’m here at the <a href="http://www.microsoft.com/en-us/default.aspx">Microsoft</a> <a href="http://www.buildwindows.com/">BUILD</a> conference in Anaheim and am very much enjoying all the announcements surrouding the next major release of Windows (at least a year or two out).&#160; One of the big speculations that has drawn a lot of confusion over the past few months is whether .Net is going to part of the next generation of Windows.&#160; It seems that Microsoft had been telegraphing quite a bit about how C++ will be the language of choice to program going into the Microsoft future.</p>
<p>Well, I’m sure that .Net is a part of Windows 8. I also now know that if you want to continue to write c# or vb code for the “new” part of Windows 8 (Metro) you can, however Microsoft has created a new API they are calling WinRT.&#160;&#160; WinRT does have a full CLR and the languages c# and vb will be supported.&#160; However, the API you call has changed.&#160; Miguel has a great article that explains much of this here:&#160; <a title="http://tirania.org/blog/archive/2011/Sep-15.html" href="http://tirania.org/blog/archive/2011/Sep-15.html">http://tirania.org/blog/archive/2011/Sep-15.html</a></p>
<p>It’s a brave new world!&#160; Much has changed, much is the same.</p>
<p>&#160;</p>
<p><a href="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/metro.jpg"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="metro" border="0" alt="metro" src="http://PetersBlogCDN.s3.amazonaws.com/wp/wp/wp-content/uploads/2011/09/metro_thumb.jpg" width="244" height="184" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/09/15/winrt-in-windows-8-clr-confusion/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>With ASP.NET WebForms, How to Keep / Stop a Data Control Like GridView From Retrieving Data</title>
		<link>http://peterkellner.net/2011/08/01/with-asp-net-webforms-how-to-keep-stop-a-data-control-like-gridview-from-retrieving-data/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=with-asp-net-webforms-how-to-keep-stop-a-data-control-like-gridview-from-retrieving-data</link>
		<comments>http://peterkellner.net/2011/08/01/with-asp-net-webforms-how-to-keep-stop-a-data-control-like-gridview-from-retrieving-data/#comments</comments>
		<pubDate>Mon, 01 Aug 2011 21:35:00 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[ASP.NET 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ObjectDataSource]]></category>
		<category><![CDATA[WebForms]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2011/08/01/with-asp-net-webforms-how-to-keep-stop-a-data-control-like-gridview-from-retrieving-data/</guid>
		<description><![CDATA[The What and Where
Something that may not be obvious is if are creating an asp.net WebForms project and you put a datasource such as SqlDataSource or ObjectDataSource for example on the page, how can you prevent the SqlSelect associated with that datasource from being triggered.
The answer is to set the control’s visible property to false.&#160; [...]]]></description>
			<content:encoded><![CDATA[<h2>The What and Where</h2>
<p>Something that may not be obvious is if are creating an asp.net <a href="http://msdn.microsoft.com/en-us/library/ms973868.aspx">WebForms</a> project and you put a datasource such as <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.aspx">SqlDataSource</a> or <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.aspx">ObjectDataSource</a> for example on the page, how can you prevent the SqlSelect associated with that datasource from being triggered.</p>
<p>The answer is to set the control’s visible property to false.&#160; That’s it!</p>
<p>  <span id="more-1529"></span>
<p>&#160;</p>
<h2>The Why</h2>
<p>The reason you might want to do this is for a case where you have a public facing web page that might be easily subjected to a denial of service attach.&#160; If that web page is always causing some SqlDataSource to fire, you could easily find your <a href="http://www.microsoft.com/sqlserver/en/us/default.aspx">SqlServer</a> overloaded.&#160; At least by checking to see a user is logged in before firing the sql statement, you buy yourself a little bit of protection.</p>
<p>&#160;</p>
<h2>The Code</h2>
<pre class="csharpcode"><span class="asp">&lt;%@ Page Language=&quot;C#&quot; %&gt;</span>

<span class="kwrd">&lt;!</span><span class="html">DOCTYPE</span> <span class="attr">html</span> <span class="attr">PUBLIC</span> <span class="kwrd">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span>
<span class="kwrd">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">script</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>

    <span class="kwrd">protected</span> <span class="kwrd">void</span>
        GridView1_SelectedIndexChanged(<span class="kwrd">object</span> sender, EventArgs e)
    {

    }

    <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Init(<span class="kwrd">object</span> sender, EventArgs e)
    {
        <span class="kwrd">if</span> (!Context.User.Identity.IsAuthenticated)
        {
            GridView1.Visible = <span class="kwrd">false</span>;
        }
    }
<span class="kwrd">&lt;/</span><span class="html">script</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;</span><span class="html">html</span> <span class="attr">xmlns</span><span class="kwrd">=&quot;http://www.w3.org/1999/xhtml&quot;</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">head</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">title</span><span class="kwrd">&gt;&lt;/</span><span class="html">title</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">head</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">=&quot;form1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">asp:SqlDataSource</span> <span class="attr">ID</span><span class="kwrd">=&quot;SqlDataSource1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span>
            <span class="attr">ConnectionString</span><span class="kwrd">=&quot;&lt;%$ ConnectionStrings:CodeCampSV06 %&gt;&quot;</span>
            <span class="attr">SelectCommand</span>=
            <span class="kwrd">&quot;SELECT [Id], [Username], [Email] FROM [Attendees] ORDER BY [Id] DESC&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">asp:SqlDataSource</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">asp:GridView</span> <span class="attr">ID</span><span class="kwrd">=&quot;GridView1&quot;</span> <span class="attr">runat</span><span class="kwrd">=&quot;server&quot;</span> <span class="attr">AutoGenerateColumns</span><span class="kwrd">=&quot;False&quot;</span>
            <span class="attr">DataKeyNames</span><span class="kwrd">=&quot;Id&quot;</span> <span class="attr">DataSourceID</span><span class="kwrd">=&quot;SqlDataSource1&quot;</span>
            <span class="attr">onselectedindexchanged</span><span class="kwrd">=&quot;GridView1_SelectedIndexChanged&quot;</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Columns</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span><span class="kwrd">=&quot;Id&quot;</span> <span class="attr">HeaderText</span><span class="kwrd">=&quot;Id&quot;</span> <span class="attr">InsertVisible</span><span class="kwrd">=&quot;False&quot;</span>
                    <span class="attr">ReadOnly</span><span class="kwrd">=&quot;True&quot;</span> <span class="attr">SortExpression</span><span class="kwrd">=&quot;Id&quot;</span> <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span><span class="kwrd">=&quot;Username&quot;</span> <span class="attr">HeaderText</span><span class="kwrd">=&quot;Username&quot;</span>
                    <span class="attr">SortExpression</span><span class="kwrd">=&quot;Username&quot;</span> <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span><span class="kwrd">=&quot;Email&quot;</span> <span class="attr">HeaderText</span><span class="kwrd">=&quot;Email&quot;</span>
                <span class="attr">SortExpression</span><span class="kwrd">=&quot;Email&quot;</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">Columns</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">asp:GridView</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">html</span><span class="kwrd">&gt;</span></pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2011/08/01/with-asp-net-webforms-how-to-keep-stop-a-data-control-like-gridview-from-retrieving-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Format Bytes in GridView Using ASP.NET (Custom asp:BoundField Server Control)</title>
		<link>http://peterkellner.net/2010/11/04/how-to-format-bytes-in-gridview-using-asp-net-custom-aspboundfield-server-control/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-format-bytes-in-gridview-using-asp-net-custom-aspboundfield-server-control</link>
		<comments>http://peterkellner.net/2010/11/04/how-to-format-bytes-in-gridview-using-asp-net-custom-aspboundfield-server-control/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 15:35:09 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/11/04/how-to-format-bytes-in-gridview-using-asp-net-custom-aspboundfield-server-control/</guid>
		<description><![CDATA[&#160;
(AKA, how to not use templates to do a simple GridView Column Formatting) 
&#160;
This post is inspired by another post on did on GridView date formatting years ago.&#160; It’s still very popular.
If you are like me, you don’t like using GridView Templates because it makes you write ugly verbose code.&#160; In this post, I’ll show [...]]]></description>
			<content:encoded><![CDATA[<h3>&#160;</h3>
<h2>(AKA, how to not use templates to do a simple GridView Column Formatting) </h2>
<p>&#160;</p>
<p>This post is inspired by another post on did on <a href="http://peterkellner.net/2006/05/24/how-to-set-a-date-format-in-gridview-using-aspnet-20using-htmlencode-property/">GridView date formatting</a> years ago.&#160; It’s still very popular.</p>
<p>If you are like me, you don’t like using <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx">GridView</a> Templates because it makes you write ugly verbose code.&#160; In this post, I’ll show you how to do a quick customization of the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.aspx">BoundField</a> asp.net&#160; server control.&#160; That is, the one you typically see in GridView as follows:</p>
<p>&#160;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/d5424563765f_7094/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/d5424563765f_7094/image_thumb.png" width="244" height="90" /></a></p>
<p>What we plan to do, is to create a custom control that looks like the following:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/d5424563765f_7094/image_3.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/d5424563765f_7094/image_thumb_3.png" width="511" height="102" /></a></p>
<p>and will end up displaying data in a table that looks like the following:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/d5424563765f_7094/image_4.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/d5424563765f_7094/image_thumb_4.png" width="447" height="208" /></a></p>
<p>  <span id="more-1385"></span>
<p>So, one approach could be to simply convert the second column into a template with GridView and build a function to call that converts the column from numbers like 267030000 to 267.3 MB.&#160; To do that, the code on the GridView will look like the following:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/d5424563765f_7094/image_5.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://peterkellner.net/FilesForWebDownload/d5424563765f_7094/image_thumb_5.png" width="616" height="193" /></a></p>
<p>And, the code behind will be as follows:</p>
<p>&#160;</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">namespace</span> GridViewExtendedBoundField{    <span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> WebForm2 : System.Web.UI.Page    {        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> Page_Load(<span style="color: #0000ff">object</span> sender, EventArgs e)        {

        }

        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">string</span> FormatToBytes(<span style="color: #0000ff">long</span> bytes)        {            <span style="color: #0000ff">return</span> FormatBytes(bytes);        }

        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> FormatBytes(<span style="color: #0000ff">long</span> bytes)        {            <span style="color: #0000ff">const</span> <span style="color: #0000ff">int</span> scale = 1024;            var orders = <span style="color: #0000ff">new</span> <span style="color: #0000ff">string</span>[] { <span style="color: #006080">&quot;GB&quot;</span>, <span style="color: #006080">&quot;MB&quot;</span>, <span style="color: #006080">&quot;KB&quot;</span>, <span style="color: #006080">&quot;Bytes&quot;</span> };            var max = (<span style="color: #0000ff">long</span>)Math.Pow(scale, orders.Length - 1);            <span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> order <span style="color: #0000ff">in</span> orders)            {                <span style="color: #0000ff">if</span> (bytes &gt; max)                    <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(<span style="color: #006080">&quot;{0:##.##} {1}&quot;</span>, <span style="color: #0000ff">decimal</span>.Divide(bytes, max), order);                max /= scale;            }            <span style="color: #0000ff">return</span> <span style="color: #006080">&quot;0 Bytes&quot;</span>;        }    }}</pre>
</div>
<div>(Code Copied from <a title="http://sharpertutorials.com/pretty-format-bytes-kb-mb-gb/" href="http://sharpertutorials.com/pretty-format-bytes-kb-mb-gb/">http://sharpertutorials.com/pretty-format-bytes-kb-mb-gb/</a>)</div>
<div>&#160;</div>
<div>This is OK for a one time use, but if you plan on doing this kind of thing a lot, I think a better way to do it is to override the BoundField control with a custom server control.&#160; Then, the code you write will look like the following and you will not need any code behind.</div>
<div>&#160;</div>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="background-color: #ffff00">&lt;%@ Register Assembly=&quot;CustomControls&quot;  Namespace=&quot;BoundControls&quot; TagPrefix=&quot;cc1&quot; %&gt;</span>...<span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:GridView</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;GridView1&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span> <span style="color: #ff0000">AutoGenerateColumns</span><span style="color: #0000ff">=&quot;False&quot;</span>            <span style="color: #ff0000">DataKeyNames</span><span style="color: #0000ff">=&quot;Id,Bytes&quot;</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">=&quot;ObjectDataSource1&quot;</span><span style="color: #0000ff">&gt;</span>  <span style="color: #0000ff">&lt;</span><span style="color: #800000">Columns</span><span style="color: #0000ff">&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">=&quot;Id&quot;</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">=&quot;Id&quot;</span> <span style="color: #ff0000">ReadOnly</span><span style="color: #0000ff">=&quot;True&quot;</span>        <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">=&quot;Id&quot;</span> <span style="color: #0000ff">/&gt;</span>    <span style="color: #0000ff">&lt;</span><span style="color: #800000">cc1:BoundFieldBytesDisplay</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">=&quot;Bytes&quot;</span> <span style="color: #ff0000">FormatAsFancyBytes</span><span style="color: #0000ff">=&quot;true&quot;</span>   <span style="color: #0000ff">&gt;</span>    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">cc1:BoundFieldBytesDisplay</span><span style="color: #0000ff">&gt;</span></pre>
<p></div>
<p>The actual custom control you have to include is simply in library reference by the Assembly CustomControls (where you can put other stuff like this).&#160; That code is as follows:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">using</span> System;<span style="color: #0000ff">using</span> System.Web.UI.WebControls;

<span style="color: #0000ff">namespace</span> BoundControls{    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> BoundFieldBytesDisplay : BoundField    {        <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> FormatAsFancyBytes        {            get            {                <span style="color: #0000ff">if</span> (ViewState[<span style="color: #006080">&quot;FormatAsFancyBytes&quot;</span>] == <span style="color: #0000ff">null</span>)                {                    <span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span>;                }                <span style="color: #0000ff">return</span> (<span style="color: #0000ff">bool</span>) ViewState[<span style="color: #006080">&quot;FormatAsFancyBytes&quot;</span>];            }            set { ViewState[<span style="color: #006080">&quot;FormatAsFancyBytes&quot;</span>] = <span style="color: #0000ff">value</span>; }        }

        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">string</span> FormatDataValue(<span style="color: #0000ff">object</span> dataValue, <span style="color: #0000ff">bool</span> encode)        {            <span style="color: #0000ff">if</span> (!FormatAsFancyBytes)            {                <span style="color: #0000ff">return</span> <span style="color: #0000ff">base</span>.FormatDataValue(dataValue, encode);            }            <span style="color: #0000ff">else</span>            {                <span style="color: #0000ff">return</span> FormatBytes(Convert.ToInt64(dataValue));            }        }

        <span style="color: #008000">/// &lt;summary&gt;</span>        <span style="color: #008000">/// http://sharpertutorials.com/pretty-format-bytes-kb-mb-gb/</span>        <span style="color: #008000">/// &lt;/summary&gt;</span>        <span style="color: #008000">/// &lt;param name=&quot;bytes&quot;&gt;&lt;/param&gt;</span>        <span style="color: #008000">/// &lt;returns&gt;&lt;/returns&gt;</span>        <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> FormatBytes(<span style="color: #0000ff">long</span> bytes)        {            <span style="color: #0000ff">const</span> <span style="color: #0000ff">int</span> scale = 1024;            var orders = <span style="color: #0000ff">new</span>[] {<span style="color: #006080">&quot;GB&quot;</span>, <span style="color: #006080">&quot;MB&quot;</span>, <span style="color: #006080">&quot;KB&quot;</span>, <span style="color: #006080">&quot;Bytes&quot;</span>};            var max = (<span style="color: #0000ff">long</span>) Math.Pow(scale, orders.Length - 1);            <span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> order <span style="color: #0000ff">in</span> orders)            {                <span style="color: #0000ff">if</span> (bytes &gt; max)                    <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(<span style="color: #006080">&quot;{0:##.##} {1}&quot;</span>, <span style="color: #0000ff">decimal</span>.Divide(bytes, max), order);                max /= scale;            }            <span style="color: #0000ff">return</span> <span style="color: #006080">&quot;0 Bytes&quot;</span>;        }    }}</pre>
<p></div>
<p>That’s basically it!&#160; Notice that in the custom control, all we have done is defined a property named “FormatAsFancyBytes” so we can set that to true.&#160; Once that happens, we simply call the FormatBytes method and it does the job we expect. If we have “FormatAsFancyBytes” false, or left out, then this control will perform identically to a BoundField control because we are calling the base class.</p>
<p>Keep in mind, you can add all kinds of special properties now to this control to handle all sorts of formatting that might be common to your business.</p>
<p>Here is the sample project build with <a href="http://www.microsoft.com/visualstudio/en-us/products/2010-editions">Visual Studio 2010</a> that demonstrates the above code.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:be9f8e87-2126-42ee-8fb2-1686a3d99203" class="wlWriterEditableSmartContent">
<div>Visual Studio 2010 Solution   <a href="http://peterkellner.net/FilesForWebDownload/d5424563765f_7094/GridViewExtendedBoundField.zip" target="_self">GridViewExtendedBoundField.zip</a></div>
</p>
</div>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:8eb9d37f-1541-4f29-b6f4-1eea890d4876:26eb3413-52b5-42d8-b591-be12a5b10f39" class="wlWriterEditableSmartContent">
<div>Visual Studio 2010 Solution   <a href="http://peterkellner.net/FilesForWebDownload/d5424563765f_7094/GridViewExtendedBoundField_3.zip" target="_self">GridViewExtendedBoundField.zip</a></div>
</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/11/04/how-to-format-bytes-in-gridview-using-asp-net-custom-aspboundfield-server-control/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Basic RIA Services And DataGrid With VS 2010 Tooling (Article 2 of 7)</title>
		<link>http://peterkellner.net/2010/01/25/basic-ria-services-and-datagrid-with-vs-2010-tooling-article-2-of-7/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=basic-ria-services-and-datagrid-with-vs-2010-tooling-article-2-of-7</link>
		<comments>http://peterkellner.net/2010/01/25/basic-ria-services-and-datagrid-with-vs-2010-tooling-article-2-of-7/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 22:51:23 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[RIA Services]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2010/01/25/basic-ria-services-and-datagrid-with-vs-2010-tooling-article-2-of-7/</guid>
		<description><![CDATA[ 



&#160;
Title Of Each Article
Video Included With Each Post


Part 1
Introduction To RIA Services In Silverlight (This Article)
7 Minutes


Part 2
Basic RIA Services And DataGrid With&#160; VS 2010 Tooling
14 Minutes


Part 3
Adding A DataGrid With Connect The Dots DataBinding in VS 2010
13 Minutes


Part 4
Adding a Navigation Page to a Silverlight Business Application Template
11 Minutes


Part 5
Adding Speakers Page Template [...]]]></description>
			<content:encoded><![CDATA[<p> <br />
<table width="90%">
<tbody>
<tr>
<td width="70">&#160;</td>
<td>Title Of Each Article</td>
<td style="width: 100px" width="150">Video Included With Each Post</td>
</tr>
<tr>
<td width="70">Part 1</td>
<td><a href="http://peterkellner.net/2010/01/20/riaservices-silverlight-4-tutorial-svcc-part1of7-introduction/">Introduction To RIA Services In Silverlight (This Article)</a></td>
<td style="width: 100px" width="150">7 Minutes</td>
</tr>
<tr>
<td width="70">Part 2</td>
<td><a href="http://peterkellner.net/2010/01/25/basic-ria-services-and-datagrid-with-vs-2010-tooling-article-2-of-7/">Basic RIA Services And DataGrid With&#160; VS 2010 Tooling</a></td>
<td style="width: 100px" width="150">14 Minutes</td>
</tr>
<tr>
<td width="70">Part 3</td>
<td><a href="http://peterkellner.net/2010/01/23/adding-a-datagrid-with-connect-the-dots-databinding-in-vs-2010-article-3-of-7/">Adding A DataGrid With Connect The Dots DataBinding in VS 2010</a></td>
<td style="width: 100px" width="150">13 Minutes</td>
</tr>
<tr>
<td width="70">Part 4</td>
<td><a href="http://peterkellner.net/2010/01/25/adding-a-navigation-page-to-a-silverlight-business-application-template-article-4-of-7/">Adding a Navigation Page to a Silverlight Business Application Template</a></td>
<td style="width: 100px" width="150">11 Minutes</td>
</tr>
<tr>
<td width="70">Part 5</td>
<td><a href="http://peterkellner.net/2010/01/25/adding-speakers-page-template-with-converters-in-visual-studio-2010-beta2-article-5-of-7/">Adding Speakers Page Template With Converters In Visual Studio 2010 Beta2</a></td>
<td style="width: 100px" width="150">11 Minutes</td>
</tr>
<tr>
<td width="70">Part 6</td>
<td><a href="http://peterkellner.net/2010/01/25/adding-a-sessions-page-that-includes-a-query-parameter-in-silverlight-vs2010-article-6-of-7/">Adding A Sessions Page That Includes a Query Parameter In Silverlight VS2010 Beta2</a></td>
<td style="width: 100px" width="150">10 Minutes</td>
</tr>
<tr>
<td width="70">Part 7</td>
<td><a href="http://peterkellner.net/2010/01/25/authentication-and-authorization-using-ria-services-article-7-of-7/">Basic Authentication and Authorization In RIA Services</a></td>
<td style="width: 100px" width="150">5 Minutes</td>
</tr>
</tbody>
</table>
<p> 
<br /><img src="http://video.peterkellner.net/video/RIAServicesBayNet20090120/P2_BasicRIANoTooling_Thumb.jpg" alt="media" /><br />

<p>&#160;</p>
<p>In this article, we will&#160; build from scratch, using Visual Studio 2010 Beta 2 a simple application that lets us view <a href="http://www.siliconvalley-codecamp.com/">Silicon Valley Code Camp</a> Attendees that have authorized us to share their data.&#160; We will be using no special RIA Services Visual Studio 2010 design tools to do this.&#160; We will:</p>
<ul>
<li>Create the <a href="http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx">Entity Framework</a> Repository </li>
<li>Create the Domain Service </li>
<li>Wire up an Appropriate Get Method that Returns in <a href="http://msdn.microsoft.com/en-us/library/system.linq.iqueryable.aspx">IQueryable</a> </li>
<li>Call From the Client Code the Domain Service </li>
<li>Show The Results </li>
<li>Observations </li>
</ul>
<p>First, we need to create a new Visual Studio Project.&#160; We do that by using the File/New Project and chose “Silverlight Business Application”.</p>
<p> <span id="more-478"></span>
<p><a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb.png" width="441" height="246" /></a></p>
<h2>Create The Entity Framework</h2>
<p>Then, we need to create an Entity Framework Repository that will be the target of our Domain Service.&#160; We do that by adding to the web project (not the top, <a href="http://silverlight.net/">Silverlight</a> project), we just created and “ADO.NET Entity Data Model”.&#160; We’ll call it ModelSVCC for Model Silicon Valley Code Camp.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb_3.png" width="456" height="258" /></a></p>
<p>We use the option “Generate From Database” as follows:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb_4.png" width="320" height="284" /></a></p>
<p>Choose the appropriate connection (in our case svcodecamp on our local Sql Server 2008 database).</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb_5.png" width="343" height="305" /></a></p>
<p>For simplicity, choose all tables and views as follows.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb_6.png" width="340" height="302" /></a></p>
<p>Do a Rebuild/All to make sure all the template code get’s generated and we are done with our first step.</p>
<h2>Create the Domain Service</h2>
<p>Next, create the Domain Service.&#160; This is done by adding again to the web project the Domain Service as follows.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb_7.png" width="372" height="211" /></a></p>
<p>Name it DomainServiceSVCC.cs again for Silicon Valley Code Camp.</p>
<p>Next check all tables and views, make sure “Enable Client Access” is checked and also “Generate associated classes for meta data”.&#160; Enable Client Access adds an attribute to the generated domain class which tell Visual Studio (on building) to generate the same domain classes on the client (Silverlight) side.&#160; This means that you are writing both your client and server code at the same time!&#160; Very convenient.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb_8.png" width="259" height="316" /></a> <a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb_9.png" width="354" height="189" /></a></p>
<p>Now, to the method generated in the Domain Service class add an OrderBy Linq command so that the method GetAttendeesWithShare has an implicit order and Skip and Take LINQ will work and the total number of records can be easily obtained (notice the yellow highlighing is the code we added, the rest was there before).</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb_10.png" width="623" height="166" /></a></p>
<p>Finally, Rebuild/All again and we are done creating the domain service class for this example.</p>
<h2>Wire up an Appropriate Get Method that Returns in IQueryable</h2>
<p>Now that we have our Domain Service built on the Server side (and of course it get’s exposed on the client side with Visual Studio 2010 template generating magic), we can go to one of the pages built in the default template, add a Silverlight DataGrid and assign our Domain Context to that. Let’s add the list of attendees to our Home Page.&#160; We do that by going to the View\Home.xaml file and simply add a DataGrid tag to the page (see below highlighted in yellow, we simply typed that in or could have dragged it from the toolbar if we are so included).</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb_11.png" width="429" height="376" /></a></p>
<p>Then, we go to the code behind of this page and add the following code to the “OnNavigateTo” enent of the Home.xaml page.</p>
<pre class="csharpcode"> var context = <span class="kwrd">new</span> DomainServiceSVCC();
 dataGrid1.ItemsSource = context.AttendeesWithShares;
 context.Load(context.GetAttendeesWithSharesQuery());</pre>
<p>
  </p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p><a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb_12.png" width="502" height="147" /></a></p>
<p>Now, when we rebuild all and run, we get:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb_13.png" width="317" height="172" /></a></p>
<p>When we click on the Id’s column header, we get the data sorted in reverse Id order, even though we never code an event for that!</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_14.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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb_14.png" width="317" height="172" /></a></p>
<h2>Observations</h2>
<p>So, what have we done?&#160; Well, we’ve done a lot. first, we’ve create a Domain Service that uses WCF on the server side.&#160; We created code on the Silverlight client that called this domain service.&#160; We got databinding right through to our output.&#160; Be very clear that in our code we added to the OnNavigate Event (repeated here)</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/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="/FilesForWebDownload/BasicRIAWithMinimalVS2010ToolingArticle2_DD97/image_thumb_12.png" width="322" height="96" /></a></p>
<p>we made a clear step across the network boundary.&#160; We created the DataService context and when we loaded it, all the async magic just happened for us.&#160; No wsdl’s, proxies to code, keep updated, etc.&#160; All that actually happens for us, but we don’t have to worry about it.&#160; I think I’m in love.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/01/25/basic-ria-services-and-datagrid-with-vs-2010-tooling-article-2-of-7/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	<enclosure url="http://video.peterkellner.net/video/RIAServicesBayNet20090120/P2_BasicRIANoTooling.flv" length="1" type="video/x-flv"/>
	</item>
		<item>
		<title>Adding A DataGrid With Connect The Dots DataBinding in VS 2010 (Article 3 of 7)</title>
		<link>http://peterkellner.net/2010/01/23/adding-a-datagrid-with-connect-the-dots-databinding-in-vs-2010-article-3-of-7/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adding-a-datagrid-with-connect-the-dots-databinding-in-vs-2010-article-3-of-7</link>
		<comments>http://peterkellner.net/2010/01/23/adding-a-datagrid-with-connect-the-dots-databinding-in-vs-2010-article-3-of-7/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 19:41:20 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[RIA Services]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[VS2010]]></category>

		<guid isPermaLink="false">http://peterkellner.net/?p=461</guid>
		<description><![CDATA[ 



&#160;
Title Of Each Article
Video Included With Each Post


Part 1
Introduction To RIA Services In Silverlight (This Article)
7 Minutes


Part 2
Basic RIA Services And DataGrid With&#160; VS 2010 Tooling
14 Minutes


Part 3
Adding A DataGrid With Connect The Dots DataBinding in VS 2010
13 Minutes


Part 4
Adding a Navigation Page to a Silverlight Business Application Template
11 Minutes


Part 5
Adding Speakers Page Template [...]]]></description>
			<content:encoded><![CDATA[<p> <br />
<table width="90%">
<tbody>
<tr>
<td width="70">&nbsp;</td>
<td>Title Of Each Article</td>
<td style="width: 100px" width="150">Video Included With Each Post</td>
</tr>
<tr>
<td width="70">Part 1</td>
<td><a href="http://peterkellner.net/2010/01/20/riaservices-silverlight-4-tutorial-svcc-part1of7-introduction/">Introduction To RIA Services In Silverlight (This Article)</a></td>
<td style="width: 100px" width="150">7 Minutes</td>
</tr>
<tr>
<td width="70">Part 2</td>
<td><a href="http://peterkellner.net/2010/01/25/basic-ria-services-and-datagrid-with-vs-2010-tooling-article-2-of-7/">Basic RIA Services And DataGrid With&nbsp; VS 2010 Tooling</a></td>
<td style="width: 100px" width="150">14 Minutes</td>
</tr>
<tr>
<td width="70">Part 3</td>
<td><a href="http://peterkellner.net/2010/01/23/adding-a-datagrid-with-connect-the-dots-databinding-in-vs-2010-article-3-of-7/">Adding A DataGrid With Connect The Dots DataBinding in VS 2010</a></td>
<td style="width: 100px" width="150">13 Minutes</td>
</tr>
<tr>
<td width="70">Part 4</td>
<td><a href="http://peterkellner.net/2010/01/25/adding-a-navigation-page-to-a-silverlight-business-application-template-article-4-of-7/">Adding a Navigation Page to a Silverlight Business Application Template</a></td>
<td style="width: 100px" width="150">11 Minutes</td>
</tr>
<tr>
<td width="70">Part 5</td>
<td><a href="http://peterkellner.net/2010/01/25/adding-speakers-page-template-with-converters-in-visual-studio-2010-beta2-article-5-of-7/">Adding Speakers Page Template With Converters In Visual Studio 2010 Beta2</a></td>
<td style="width: 100px" width="150">11 Minutes</td>
</tr>
<tr>
<td width="70">Part 6</td>
<td><a href="http://peterkellner.net/2010/01/25/adding-a-sessions-page-that-includes-a-query-parameter-in-silverlight-vs2010-article-6-of-7/">Adding A Sessions Page That Includes a Query Parameter In Silverlight VS2010 Beta2</a></td>
<td style="width: 100px" width="150">10 Minutes</td>
</tr>
<tr>
<td width="70">Part 7</td>
<td><a href="http://peterkellner.net/2010/01/25/authentication-and-authorization-using-ria-services-article-7-of-7/">Basic Authentication and Authorization In RIA Services</a></td>
<td style="width: 100px" width="150">5 Minutes</td>
</tr>
</tbody>
</table>
<p> 
<br /><img src="http://video.peterkellner.net//video/RIAServicesBayNet20090120/P3_DataGridWithVSToolingBusyIndicatorAndPaging_Thumb.jpg" alt="media" /><br />

<p> 
<p>In this article, we will use the the Visual Studio 2010 Beta2 Tooling to create a Sessions DataGrid.&nbsp; We will add a Pager to it as well as a Silverlight busy indicator which will show while the data is loading.&nbsp; In Article 1, we build a simple DataGrid with code behind, in this article, it will all be declarative in XAML built with the Visual Studio 2010 designer.</p>
<p><span id="more-461"></span>
<p>First thing we need to do is add a new Silverlight Navigation Page to the Silverlight project (not the web project) in the Views folder.</p>
<p>&nbsp;<a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb.png" width="433" height="183"></a></p>
<p>Then, copy the code from the Home Page to get the top two default sections that appear on every page as follows:</p>
<p>&nbsp;<a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_3.png" width="437" height="163"></a></p>
<p>And the actual code:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --><br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}</p>
<p>.csharpcode pre { margin: 0em; }</p>
<p>.csharpcode .rem { color: #008000; }</p>
<p>.csharpcode .kwrd { color: #0000ff; }</p>
<p>.csharpcode .str { color: #006080; }</p>
<p>.csharpcode .op { color: #0000c0; }</p>
<p>.csharpcode .preproc { color: #cc6633; }</p>
<p>.csharpcode .asp { background-color: #ffff00; }</p>
<p>.csharpcode .html { color: #800000; }</p>
<p>.csharpcode .attr { color: #ff0000; }</p>
<p>.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}</p>
<p>.csharpcode .lnum { color: #606060; }
</style>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">x:Name</span><span class="kwrd">="ContentStackPanel"</span>
            <span class="attr">Style</span><span class="kwrd">="{StaticResource ContentStackPanelStyle}"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">x:Name</span><span class="kwrd">="HeaderText"</span> <span class="attr">Style</span><span class="kwrd">="{StaticResource HeaderTextStyle}"</span>
               <span class="attr">Text</span><span class="kwrd">="{Binding Path=ApplicationStrings.HomePageTitle,
               Source={StaticResource ResourceWrapper}}"</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">x:Name</span><span class="kwrd">="ContentText"</span> <span class="attr">Style</span><span class="kwrd">="{StaticResource ContentTextStyle}"</span>
               <span class="attr">Text</span><span class="kwrd">="Home page content"</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Image</span> <span class="attr">Height</span><span class="kwrd">="393"</span> <span class="attr">Name</span><span class="kwrd">="image1"</span> <span class="attr">Stretch</span><span class="kwrd">="Uniform"</span> <span class="attr">Width</span><span class="kwrd">="467"</span>
               <span class="attr">Source</span><span class="kwrd">="/Presentation1;component/Images/IMG_1504.JPG"</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span></pre>
<p>Change text to “Speaker page content” and change the resource string to ApplicationString.SpeakerPageTitle and update the ApplicationStrings.resx file as follows:</p>
<p>&nbsp;<a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_4.png" width="405" height="286"></a></p>
<p>Then, drag a DataGrid to the Speaker.xaml design surface (after removing the image tag which was the picture on the home page we copied over).</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_5.png" width="549" height="213"></a></p>
<p>Now, we do what Microsoft calls “Connect the Dots DataBinding”.&nbsp; That is, we go to the Data Sources Tab</p>
<p>&nbsp;<a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_6.png" width="352" height="168"></a></p>
<p>Drag the SpeakersShort2009 box (shown in yellow below) to the DataGrid showing on the design surface.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_7.png" width="348" height="149"></a></p>
<p>That automatically creates a bunch of xaml including the RIA Domain DataSource, which includes a reference to the correct query method and the correct Domain Context.&nbsp; Very nice!</p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}</p>
<p>.csharpcode pre { margin: 0em; }</p>
<p>.csharpcode .rem { color: #008000; }</p>
<p>.csharpcode .kwrd { color: #0000ff; }</p>
<p>.csharpcode .str { color: #006080; }</p>
<p>.csharpcode .op { color: #0000c0; }</p>
<p>.csharpcode .preproc { color: #cc6633; }</p>
<p>.csharpcode .asp { background-color: #ffff00; }</p>
<p>.csharpcode .html { color: #800000; }</p>
<p>.csharpcode .attr { color: #ff0000; }</p>
<p>.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}</p>
<p>.csharpcode .lnum { color: #606060; }
</style>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">riaControls:DomainDataSource</span> <span class="attr">AutoLoad</span><span class="kwrd">="True"</span> <span class="attr">Height</span><span class="kwrd">="0"</span>
                                      <span class="attr">LoadedData</span><span class="kwrd">="speakersShort2009DomainDataSource_LoadedData"</span>
                                      <span class="attr">Name</span><span class="kwrd">="speakersShort2009DomainDataSource"</span>
                                      <span class="attr">QueryName</span><span class="kwrd">="GetSpeakersShort2009Query"</span> <span class="attr">Width</span><span class="kwrd">="0"</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">riaControls:DomainDataSource.DomainContext</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span class="html">my:DomainServiceSVCC</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span class="html">riaControls:DomainDataSource.DomainContext</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">riaControls:DomainDataSource</span><span class="kwrd">&gt;</span></pre>
<p>
<pre class="csharpcode"><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_8.png" width="599" height="195"></a></pre>
<pre class="csharpcode"></pre>
<p><!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->Now, we do the same thing with the DataPager (which may have to add to the toolbox with “Choose Items” That gives us some xaml that looks like the following.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_9.png" width="423" height="287"></a></p>
<p>&nbsp;</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_10.png" width="419" height="246"></a></p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">data:DataPager</span> <span class="attr">Height</span><span class="kwrd">="26"</span>
                <span class="attr">HorizontalAlignment</span><span class="kwrd">="Left"</span> <span class="attr">Margin</span><span class="kwrd">="720,325,0,0"</span>
                <span class="attr">Name</span><span class="kwrd">="dataPager1"</span> <span class="attr">VerticalAlignment</span><span class="kwrd">="Top"</span>
                <span class="attr">Width</span><span class="kwrd">="200"</span>
                <span class="attr">PageSize</span><span class="kwrd">="10"</span><span class="kwrd">/&gt;</span></pre>
<pre class="csharpcode"><span class="kwrd"></span>&nbsp;</pre>
<p><!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>Notice that I put PageSize in.&nbsp; That does not happen by default, and in my presentation, I forgot this and for a while could not figure out why the paging was not working.&nbsp; Try and not make the same mistake!</p>
<p>Then, drag the same DataSource as we dragged to the DataGrid and drop it on the Paging control as follows:</p>
<p>&nbsp;<a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_11.png" width="412" height="135"></a></p>
<p>That automatically binds the DataPager to the same DomainDataSource as the DataGrid’s DomainDataSource.&nbsp; Here is the XAML created.</p>
<pre class="csharpcode"> <span class="kwrd">&lt;</span><span class="html">data:DataPager</span> <span class="attr">Height</span><span class="kwrd">="26"</span> <span class="attr">Name</span><span class="kwrd">="dataPager1"</span> <span class="attr">Width</span><span class="kwrd">="200"</span>
   <span class="attr">Source</span><span class="kwrd">="{Binding ElementName=speakersShort2009DomainDataSource, Path=Data}"</span> <span class="kwrd">/&gt;</span></pre>
<pre class="csharpcode"></pre>
<p><!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->The next thing is to use the new “Reset-All” for styling.&nbsp; It’s very simple.&nbsp; Right click on the design surface and simply click “Layout/Reset” as follows:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_12.png" width="244" height="176"></a></p>
<p>Now, when we run this, we get:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_13.png" width="380" height="366"></a></p>
<p>Finally, to put a “Busy Indicator” control on the page, we simply drag out the busy Indicator onto the design surface. It likely will not be in your toolbox, so like the DataPager, you will need to add it to the toolbar as follows:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_14.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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_14.png" width="396" height="252"></a></p>
<p>Then, drag it from the toolbox right onto the DataGrid as follows:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_15.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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_15.png" width="297" height="314"></a></p>
<p>Then, once it’s on the DataGrid (and in the XAML), you need to right click on it and change some of it’s properties.</p>
<p>First, set the “IsBusy” property by checking the checkbox, then resize the control itself so it shows the text and is a pleasant size.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_16.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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_16.png" width="428" height="280"></a></p>
<p>The next step is a little more tricky.&nbsp; You need to find the property in the BusyIndicator called DataContext. Right click on that as follows and press “Apply Data Binding”.</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_17.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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_17.png" width="428" height="257"></a></p>
<p>Now, you are setting the Source so first select “ElementName”, then chose speakersShort2009DomainDataSource as follows:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_18.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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_18.png" width="431" height="296"></a></p>
<p>Then, go to the “Path:” and set the property “DomainContext” and the method to “IsLoading” as follows:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_19.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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_19.png" width="436" height="254"></a></p>
<p>What this has done is created a binding expression using a very nice Visual Studio 2010 Tool.&nbsp; It’s assigned that binding expression to the DataContext of the DomainDataSource.</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">riaControls:DomainDataSource</span> <span class="attr">AutoLoad</span><span class="kwrd">="True"</span> <span class="attr">Height</span><span class="kwrd">="0"</span>
         <span class="attr">LoadedData</span><span class="kwrd">="speakersShort2009DomainDataSource_LoadedData_2"</span>
                              <span class="attr">Name</span><span class="kwrd">="speakersShort2009DomainDataSource"</span>
                              <span class="attr">QueryName</span><span class="kwrd">="GetSpeakersShort2009Query"</span> <span class="attr">Width</span><span class="kwrd">="0"</span>
   <span class="attr">DataContext</span><span class="kwrd">="{Binding ElementName=speakersShort2009DomainDataSource, Path=DomainContext.IsLoading}"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">riaControls:DomainDataSource.DomainContext</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">my:DomainServiceSVCC</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">riaControls:DomainDataSource.DomainContext</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">riaControls:DomainDataSource</span><span class="kwrd">&gt;</span></pre>
<p><!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->Now, when we finally run our program, we first get the busy indicator as the data is being asynchrously loaded which looks like this:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_20.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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_20.png" width="514" height="180"></a></p>
<p>Then, when the data finally loads, looks like the following:</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_21.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://peterkellner.net/FilesForWebDownload/AddingDataGridWithVS2010ToolingArticle3o_E48C/image_thumb_21.png" width="523" height="449"></a></p>
<p>Notice the paging control at the bottom, and notice the BusyIndicator has gone away.</p>
<p>That’s it for this article.&nbsp; In the next article, we will style this page as well as add Converts to show the Speakers picture and add a hyperlink to the sessions associated with each speaker.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2010/01/23/adding-a-datagrid-with-connect-the-dots-databinding-in-vs-2010-article-3-of-7/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	<enclosure url="http://video.peterkellner.net//video/RIAServicesBayNet20090120/P3_DataGridWithVSToolingBusyIndicatorAndPaging.flv" length="1" type="video/x-flv"/>
	</item>
		<item>
		<title>How to Get a Stack Trace from C# without throwing Exception</title>
		<link>http://peterkellner.net/2009/12/21/how-to-get-a-stack-trace-from-c-without-throwing-exception/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-get-a-stack-trace-from-c-without-throwing-exception</link>
		<comments>http://peterkellner.net/2009/12/21/how-to-get-a-stack-trace-from-c-without-throwing-exception/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 16:48:54 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/12/21/how-to-get-a-stack-trace-from-c-without-throwing-exception/</guid>
		<description><![CDATA[Say you have some logging in your code that finds something unusual going on.&#160; In my case, I have a DataContext that I check to make sure it’s not already open before I open it.&#160; The method that I call the DataContext in is a utility method that is buried many layers down.&#160; When this [...]]]></description>
			<content:encoded><![CDATA[<p>Say you have some logging in your code that finds something unusual going on.&#160; In my case, I have a DataContext that I check to make sure it’s not already open before I open it.&#160; The method that I call the DataContext in is a utility method that is buried many layers down.&#160; When this problem is found, I don’t want to throw an exception, but I do want to log where I was.&#160; It does not help me to know that I’m in my utility method.&#160; I need to know the <a href="http://msdn.microsoft.com/en-us/library/system.environment.stacktrace.aspx">stack</a>.</p>
<p> <span id="more-398"></span>
<p>Below is some simple code that lets me do this.&#160; Notice, it’s important to call <a href="http://msdn.microsoft.com/en-us/library/aa326974%28VS.71%29.aspx">StackTrace</a> with true, otherwise the line numbers don’t appear.</p>
<p>HTH’s!</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.Diagnostics;
<span class="kwrd">using</span> System.Linq;
<span class="kwrd">using</span> System.Text;

<span class="kwrd">namespace</span> ConsoleApplication1
{
    <span class="kwrd">class</span> Program
    {
        <span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)
        {
            TestClass.GoNow();
        }
    }

    <span class="kwrd">class</span> TestClass
    {
        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> GoNow()
        {
            var stackTrace = <span class="kwrd">new</span> StackTrace(<span class="kwrd">true</span>);
            <span class="kwrd">foreach</span> (var r <span class="kwrd">in</span> stackTrace.GetFrames())
            {
                Console.WriteLine(<span class="str">&quot;Filename: {0} Method: {1} Line: {2} Column: {3}  &quot;</span>,
                    r.GetFileName(),r.GetMethod(), r.GetFileLineNumber(),
                    r.GetFileColumnNumber() );
            }
        }
    }

}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/12/21/how-to-get-a-stack-trace-from-c-without-throwing-exception/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Long Live the Semicolon and Why I Love it!</title>
		<link>http://peterkellner.net/2009/10/24/usethesemicolonornot/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=usethesemicolonornot</link>
		<comments>http://peterkellner.net/2009/10/24/usethesemicolonornot/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 15:23:55 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/10/24/usethesemicolonornot/</guid>
		<description><![CDATA[ OK, so we all want to be somewhat popular, and it seems that my last article, “To Brace Or Not to Brace”, seems to have gotten a lot of attention, so, here goes my opinion on the popular semi-colon argument.&#160; First, I’m not against any languages in particular, but I have found that I [...]]]></description>
			<content:encoded><![CDATA[<p> OK, so we all want to be somewhat popular, and it seems that my last article, <a href="http://peterkellner.net/2009/10/19/codingstandards-csharp-braces/">“To Brace Or Not to Brace”,</a> seems to have gotten a lot of attention, so, here goes my opinion on the popular semi-colon argument.&#160; First, I’m not against any languages in particular, but I have found that I do better in ones that have semi-colons.&#160; One of the features I really like is the ability to move my line returns anyplace I want, and to indent as I see fit.&#160; Though the semi-colon does not guarantee I can do this, it certainly makes life easier.</p>
<p> <span id="more-370"></span>
<p>So, what’s wrong with using tabs to signal nesting levels and dispense with semi-colons?&#160; Well, for me, that is just too hard.&#160; I always seem to mess up and my code stops working.&#160; What about line continuations?&#160; I just have to ask why?&#160; Want to continue, just press the return key.&#160; Not much else to remember.</p>
<p>In College, I learned a language called PL/1 (long forgotten) that required semi-colons.&#160; I remember the compiler would constantly spit out errors saying “Maybe you have missed your semi-colon?”.&#160; I use to find that very annoying, but now, that I’m a semicolon lover, I just happily type them at the end of each statement I want terminated.</p>
<p>There are dissenters however.&#160; For example, the TheMightyFavog says <a href="http://www.democraticunderground.com/discuss/duboard.php?az=view_all&amp;address=105x6098021">“Let’s get rid of it.&#160; Nobody knows how to use the thing anyway</a>”. </p>
<p>Just my 2 cents.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/10/24/usethesemicolonornot/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Visiting Our First Silicon Valley Code Camp Platinum Sponsor for 2009</title>
		<link>http://peterkellner.net/2009/08/16/visiting-our-first-silicon-valley-code-camp-platinum-sponsor-for-2009/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=visiting-our-first-silicon-valley-code-camp-platinum-sponsor-for-2009</link>
		<comments>http://peterkellner.net/2009/08/16/visiting-our-first-silicon-valley-code-camp-platinum-sponsor-for-2009/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 18:23:59 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/08/16/visiting-our-first-silicon-valley-code-camp-platinum-sponsor-for-2009/</guid>
		<description><![CDATA[ This past Thursday evening, my wife Tammy and I went to visit our first platinum sponsor of 2009, Falafel Software in Capitola California.&#160; Lino Tadros, Chairman and CEO of Falafel let us use his office for normal working during the day, then we all went out for a great Sushi meal after.&#160; Falafel provides [...]]]></description>
			<content:encoded><![CDATA[<p> This past Thursday evening, my wife Tammy and I went to visit our first platinum sponsor of 2009, <a href="http://www.falafel.com/">Falafel Software</a> in Capitola California.&#160; Lino Tadros, Chairman and CEO of Falafel let us use his office for normal working during the day, then we all went out for a great Sushi meal after.&#160; Falafel provides high qualtiy software development, consulting and training.&#160; We had the chance to see where it all happens.</p>
<p> <span id="more-343"></span>
<p><a href="http://www.siliconvalley-codecamp.com">http://www.siliconvalley-codecamp.com</a> (come!)</p>
<p>Thanks for hosting!</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/VisitingOurFirstSiliconValleyCodeCampPla_9EFC/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://peterkellner.net/FilesForWebDownload/VisitingOurFirstSiliconValleyCodeCampPla_9EFC/image_thumb.png" width="244" height="164" /></a> <a href="http://peterkellner.net/FilesForWebDownload/VisitingOurFirstSiliconValleyCodeCampPla_9EFC/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://peterkellner.net/FilesForWebDownload/VisitingOurFirstSiliconValleyCodeCampPla_9EFC/image_thumb_3.png" width="244" height="243" /></a></p>
<p>At Gayles Deli, then in the Falafel Office</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/08/16/visiting-our-first-silicon-valley-code-camp-platinum-sponsor-for-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bravo for ORCSWeb! On so many fronts</title>
		<link>http://peterkellner.net/2009/07/27/orcsweb-hosting-company-awesome-review/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=orcsweb-hosting-company-awesome-review</link>
		<comments>http://peterkellner.net/2009/07/27/orcsweb-hosting-company-awesome-review/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 19:59:07 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[Code Camp Web Site Series]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Sql Server 2008]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/07/27/orcsweb-hosting-company-awesome-review/</guid>
		<description><![CDATA[Many of you know of ORCSWeb either by reputation, or by way of Scott Forsyth, one of my ASP.NET MVP brothers.&#160; In case you don’t, they are a managed hosting solutions company specializing in Microsoft technologies.&#160; I’ve used their basic services for quite a while and have always been very happy.&#160; It has always seemed [...]]]></description>
			<content:encoded><![CDATA[<p>Many of you know of <a href="http://www.orcsweb.com/">ORCSWeb</a> either by reputation, or by way of <a href="http://weblogs.asp.net/owscott/default.aspx">Scott Forsyth</a>, one of my ASP.NET MVP brothers.&#160; In case you don’t, they are a managed hosting solutions company specializing in Microsoft technologies.&#160; I’ve used their basic services for quite a while and have always been very happy.&#160; It has always seemed that anytime I’ve called them (and it always seems like the middle of the night) one of their tech support staff is always available to help me, and go the extra mile if necessary.</p>
<p>The company I’m now working at is small and we don’t have a lot of resources to maintain hardware and do operating system type support.&#160; We do have a high load requirement so we need a very robust supported solution.&#160; Before this, I’d always been in the under $50 per month type plan with ORCSWeb, but I decided I needed more servers and a higher level of support.&#160; I really did not know what level of support to expect when signing up for the managed servers but decided to go for it anyway.</p>
<p>All&#160; can say is <strong>WOW!!!</strong>&#160; I am over the top impressed. </p>
<p> <span id="more-337"></span>
<p>We currently have 3 virtual servers hosted at ORCSWeb.&#160; One, we use as a development server, and the other two are in a webfarm configuration.&#160; I’ve always believed that when you go into production with a web site it’s critical you start with 2 servers in a webfarm.&#160; it’s really easy to go from 2 to 10, but can be very painful to go from 1 to 2.&#160;&#160; That’s a topic for another post, but suffice it to say, 2 is the minimum.</p>
<p>So, why am I so impressed?&#160; First, the support team they assigned to me is totally awesome.&#160; They all are focussed and competent which is a total relief compared with most hosting companies I’ve dealt with.&#160; Other companies always have good people, but it seems to be the bad ones that really give me cause to remember.&#160; Second, because I paid extra for the full managed support options on our three servers, I’ve been able to ask the things like the following.&#160; Almost all of them I could do myself, but I’m swamped with my technology role in the new company and really appreciate being able to hand stuff like this off.</p>
<ul>
<li>I’ve pointed my MX record at my .149 server.&#160; Could you please set up email and create the following 7 accounts. </li>
<li>Please Setup a secure ftp server at the following address with the following username and password (and make sure the user is locked down to the root) </li>
<li>Setup DFS Replication between these two directories on .148 and .149 </li>
<li>Create a RoboCopy script that copies files from my dev server to the .149 mirrored directory </li>
<li>Please set up web statistics for me on <a href="http://www.siliconvalley-codecamp.com">http://www.siliconvalley-codecamp.com</a> </li>
<li>Please figure out why SqlServer 2008 is not letting me access catalog MyStuff1 from user 3p1 and fix </li>
<li>Please make a replicate of website MyWeb1.com including the sqlserver catalog’s and put it on MyWeb2.com on server .149 </li>
<li>Please replace the sqlserver catalog MyStuff3 on server .149 with the bak file I uploaded to my ftp server </li>
<li>I could go on and on, but I think you are getting the idea. </li>
<li>Always with a smile, 24&#215;7, what else can I say. </li>
</ul>
<p>By the way, if you want to see one of my sites hosted there, go to <a href="http://www.siliconvalley-codecamp.com">http://www.siliconvalley-codecamp.com</a></p>
<p>Thank you <a href="http://www.orcsweb.com/">ORCSWeb</a> for making things a lot easier for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/07/27/orcsweb-hosting-company-awesome-review/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>In ASP.NET, How To Create a DropDownList from an ENUM</title>
		<link>http://peterkellner.net/2009/06/16/in-aspnet-how-to-create-a-dropdownlist-from-an-enum/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=in-aspnet-how-to-create-a-dropdownlist-from-an-enum</link>
		<comments>http://peterkellner.net/2009/06/16/in-aspnet-how-to-create-a-dropdownlist-from-an-enum/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 23:05:14 +0000</pubDate>
		<dc:creator>Peter Kellner</dc:creator>
				<category><![CDATA[ASP.NET 2.0]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://peterkellner.net/2009/06/16/in-aspnet-how-to-create-a-dropdownlist-from-an-enum/</guid>
		<description><![CDATA[ So, you have an enum defined as follows:
public enum CompanyAddressType
    {
        Unknown = 0,
        Primary = 1,
        Warehouse = 2,
        Distribution_Center = 3,
 [...]]]></description>
			<content:encoded><![CDATA[<p> So, you have an enum defined as follows:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">enum</span> CompanyAddressType
    {
        Unknown = 0,
        Primary = 1,
        Warehouse = 2,
        Distribution_Center = 3,
        Cross_Dock = 4
    }</pre>
<p>You want to iterate through the list and put the data into an asp.net dropdownlist.</p>
<p><span id="more-326"></span></p>
<p>Here is the simple code:</p>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)
        {
            <span class="kwrd">if</span> (!IsPostBack)
            {
                <span class="kwrd">string</span>[] names = Enum.GetNames(<span class="kwrd">typeof</span>(CompanyAddressType));
                var values = (CompanyAddressType[])Enum.GetValues(<span class="kwrd">typeof</span>(CompanyAddressType));
                <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; names.Length; i++)
                {
                    DropDownListCompanyAddressType.Items.Add(<span class="kwrd">new</span> ListItem(names[i], values.ToString()));
                }
            }
        }</pre>
<p>&#160;</p>
<p>There are probably easier ways to do it, but this works.</p>
<p>and…</p>
<p><a href="http://peterkellner.net/FilesForWebDownload/InA.NETHowToCreateaDropDownListfromanENU_E21B/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://peterkellner.net/FilesForWebDownload/InA.NETHowToCreateaDropDownListfromanENU_E21B/image_thumb.png" width="246" height="154" /></a></p>
<p>HTH’s.</p>
]]></content:encoded>
			<wfw:commentRss>http://peterkellner.net/2009/06/16/in-aspnet-how-to-create-a-dropdownlist-from-an-enum/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 31/40 queries in 0.020 seconds using disk: basic
Content Delivery Network via Amazon Web Services: S3: PetersBlogCDN.s3.amazonaws.com

Served from: peterkellner.net @ 2012-05-22 09:38:04 -->
