<?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>Visoft, Inc. Blogs &#187; WCF Data Services</title>
	<atom:link href="http://blogs.visoftinc.com/category/wcf-data-services/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.visoftinc.com</link>
	<description>.NET, ASP.NET, AJAX, Ruby and more</description>
	<lastBuildDate>Mon, 12 Mar 2012 18:05:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Major Ruby OData Update v0.1.0</title>
		<link>http://blogs.visoftinc.com/2011/12/07/major-ruby-odata-update-v0-1-0/</link>
		<comments>http://blogs.visoftinc.com/2011/12/07/major-ruby-odata-update-v0-1-0/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 04:40:41 +0000</pubDate>
		<dc:creator>Damien White</dc:creator>
				<category><![CDATA[OData]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ruby_odata]]></category>
		<category><![CDATA[WCF Data Services]]></category>
		<category><![CDATA[WCF]]></category>
		<guid isPermaLink="false">http://blogs.visoftinc.com/?p=263</guid>
		<description><![CDATA[It’s here! I’m happy to announce a major release of ruby_odata, v0.1.0. There are many enhancements found in this release so let’s dig in and see what’s new. There is one thing that we need to get out of the way first, a breaking change. In v0.0.10 and below, queries and some instances of calls [...]]]></description>
			<content:encoded><![CDATA[<p><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 10px 15px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="OData_logo_MS_small_thumb7" border="0" alt="OData_logo_MS_small_thumb7" align="right" src="http://blogs.visoftinc.com/wp-content/uploads/2011/12/OData_logo_MS_small_thumb7.png" width="300" height="37" />It’s here! I’m happy to announce a major release of <a href="https://github.com/visoft/ruby_odata/" target="_blank">ruby_odata</a>, v0.1.0. There are many enhancements found in this release so let’s dig in and see what’s new.</p>
<p>There is one thing that we need to get out of the way first, a <strong>breaking change</strong>. In v0.0.10 and below, queries and some instances of calls to <code>save_changes</code> would return a single entity if there was only one returned. This was confusing and could lead to errors. As a consumer of the gem, you wouldn’t know if a call to the Service’s <code>execute</code> method was a single object or an enumerable. Instead of you having to guess, those calls now return enumerables all the time. This applies to calls to <code>execute</code> and <code>save_change</code> additions. Updates, deletes, and <code>add_link</code> calls (we’ll get to those in a minute), as well as batch saves all return Booleans, but single <code>save_change</code> add calls will return an enumerable because those results are parsed similar to <code>execute</code> calls.</p>
<p>Now that that’s out of the way, let’s look at the new features.</p>
<p><span id="more-263"></span><br />
<h2>The Features</h2>
<h3>Partial Results</h3>
<p>The first change is thanks to <a href="https://github.com/arienmalec" target="_blank">arienmalec</a>. OData allows services to do server-side paging in Atom by defining a next link. The default behavior is to repeatedly consume partial feeds until the result set is complete, for example:</p>
<pre class="brush: ruby;">svc.Partials
results = svc.execute # =&gt; retrieves all results in the Partials collection</pre>
<p>If desired (e.g., because the result set is too large to fit in memory), explicit traversal of partial results can be requested via options:</p>
<pre class="brush: ruby;">svc = OData::Service.new &quot;http://example.com/Example.svc&quot;, { :eager_partial =&gt; false }
svc.Partials
results = svc.execute # =&gt; retrieves the first set of results returned by the server
if svc.partial? # =&gt; true if the last result set was a partial result set (i.e., had a next link)
  results.concat svc.next # =&gt; retrieves the next set of results
end
while svc.partial? # =&gt; to retrieve all partial result sets
  results.concat svc.next
end</pre>
<h3>Single Layer Inheritance</h3>
<p>This feature was long overdue! Back in July 2010, <a href="http://odetocode.com/Blogs/scott/articles/about-scott-allen.aspx" target="_blank">Scott Allen</a> wrote <a href="http://odetocode.com/Blogs/scott/archive/2010/07/11/odata-and-ruby.aspx" target="_blank">a post about ruby_odata</a> where he mentioned a change to the Service class that would parse models with single layer inheritance. His code has finally been integrated into ruby_odata. Note, that the addition currently only support single layer inheritance, but that should handle most of the cases you will encounter.</p>
<h3>Querying Links</h3>
<p>There are times when you don’t necessarily want to bring down full navigation property entities. In these cases the OData protocol has support for <a href="http://www.odata.org/developers/protocols/uri-conventions#AddressingLinksBetweenEntries" target="_blank">Addressing Links Between Entities</a>. To support this, there is a new method that can be tacked on to a single entity query (e.g. finding an entity by id) called <code>links</code> where you pass the name of the navigation property of the links that you want to retrieve. For example:</p>
<pre class="brush: ruby;">svc.Categories(1).links(&quot;Products&quot;)
product_links = svc.execute # =&gt; returns URIs for the products</pre>
<h3>Add Link</h3>
<p>There are times when you need to <a href="http://www.odata.org/developers/protocols/operations#CreatingLinksbetweenEntries" target="_blank">create a linkage between a parent and a child</a>, and you don’t want be required to perform an add or update. You can now simply call the <code>add_link</code> method on the <code>OData::Service</code> with the parent object, the name of the navigation property, and the child object. Finally, call <code>save_changes</code>. For example:</p>
<pre class="brush: ruby;">svc.add_link(&lt;Parent&gt;, &lt;Navigation Property Name&gt;, &lt;Child&gt;)
svc.save_changes</pre>
<h3>Lazy Loading</h3>
<p>In previous versions of ruby_odata, if you wanted to perform lazy loading of navigation properties you would need to do it manually, which was extremely ugly. I’m happy to say that there is now a way to perform lazy loading in a graceful way. All you need to do is to call the <code>load_property</code> method on the <code>OData::Service</code> with the entity to fill and the name of the navigation property. For example:</p>
<pre class="brush: ruby;"># Without expanding the query
svc.Products(1)
prod1 = svc.execute.first
# Use load_property for lazy loading
svc.load_property(prod1, &quot;Category&quot;)</pre>
<h3>Reflection / Introspection</h3>
<p>Paul Gallagher (<a href="https://github.com/tardate" target="_blank">tardate</a>) had a <a href="https://github.com/visoft/ruby_odata/issues/11" target="_blank">great suggestion</a>: Why should you have to look at the EDMX metadata file directly when ruby_odata parses all that data? You can now use the <code>OData::Service</code> to access a list of the <code>collections</code> that the service exposes. There is also a <code>classes</code> method, which gives you a list of the classes generated by the OData::Service. A <code>function_imports</code> method, which will list function imports exposed by the service (we’ll get to those in a minute). On a class, you can call the class method, <code>properties</code>, which as you guessed will give you information about each property. Each of these methods return hashes where the keys are the name, and the values are hashes of the metadata for the member that you are introspecting.</p>
<h3>Function Imports</h3>
<p>Quite a while ago, I received an message from a user via this blog asking about the ability to call custom service methods. Within a WCF Data Service, you can expose your own custom methods, which get translated into the <a href="http://www.odata.org/media/6652/[mc-csdl][1].htm#_Toc246717555" target="_blank">EDMX as FunctionImports</a>. These aren’t to be confused with Entity Framework’s <code>FunctionImports</code>. These will be parsed and dynamically added as methods to the <code>OData::Service</code>. When you call one of the methods, they will return a result without you needing to make a call to <code>execute</code> or <code>save_changes</code>. There are different result types. You may get back a true if the <code>FunctionImport</code> doesn’t return any content (for example, a delete). You may get back a single entity, or a collection of entities. Finally, you may get back a single primitive value (e.g. Integer, String, etc), or a collection of primitive values. You can use the <code>function_imports</code> method on the Service to determine the type that will be returned.</p>
<h3>Namespaces</h3>
<p>In the same message as the request for the custom service methods (ok, it was actually a reply), the user mentioned that he received type conflicts with the generated classes if one by the same name already existed. If this is a problem for you, you now have the ability to tell the <code>OData::Service</code> to generate the models in a specific namespace. There is a new option that can be passed in to the constructor’s option hash, <code>:namespace</code>. If you use this option, there shouldn’t be any collisions. You can pass a namespace in either Ruby (with double colons, e.g. <code>RubyOData::Rocks</code>) or .NET style (with periods, e.g. <code>RubyOData.Rocks</code>) if there is more than one part to the namespace that you want to use. If you don’t provide a namespace, then ruby_odata will generate the classes without any namespace just as it has before.</p>
<h3>The Beginnings of Something Cool?</h3>
<p>As developers, the majority of the time we either retrieve collections or a single entity, usually by an ID. I didn’t really like the current steps to retrieve a single entity by ID:</p>
<pre class="brush: ruby;">svc.Categories(1)
category = svc.execute.first</pre>
<p>Sort of ugly, right? So inspired by Ruby on Rails, I added a class method for each created class so that you could just do this:</p>
<pre class="brush: ruby;">category = Category.first(1)</pre>
<p>Great, right? It’s a little nicer, but sadly it’s a one trick pony right now. There’s no filtering, eager loading, etc. My idea was to hopefully expand on the concept like Rails and ActiveRecord, but for now it’s just an easier, cleaner way to get an entity.</p>
<h2>Testing</h2>
<p>In addition to the new features, I’ve been busy working on the testing suite. </p>
<h3>No More Hardcoded URIs</h3>
<p>Having to rely on Windows for testing has made me stick to Windows and e-TextEditor for ruby_odata development. The key word there is actually testing. All that Windows is required for is hosting the WCF Data Service for the Cucumber integration tests, but Cucumber is just one part of it, RSpec is the other. It’s no denying that Ruby on Windows is slower than its *nix counterparts (not to knock the RubyInstaller.com team, if it wasn’t for them, Ruby on Windows would be non-existent). Where you really see a slowdown is when you are doing TDD/BDD testing. You need tests to run fast, and if you ran the command <code>time rake spec</code>, my Windows box is more than 4 times slower than my old MacBook (note, not a Pro), which has similar hardware. Now, multiply that by every spec I write and I want to throw my machine out a window. So, in an effort to migrate development, the URLs and ports required for the sample WCF service are now dynamic. Take a look at features/support/constants.rb for more information. Thanks to Sean Carpenter (<a href="https://github.com/scarpenter" target="_blank">scarpenter</a>) for his fork where he changed the static values in that file to be optionally set by environment variables.</p>
<h3>Hello New Technology</h3>
<p>I decided to change up the technologies used within the test service. First, no more SQL Express, hello SQL Compact 4. Why the change? SQL Compact 4 is simply DLL deployed, you don’t need to install anything, cool. Also, since SQL Compact 4 databases are file based, instead of having to truncate to clean the database for testing, the file could just be blown away and rebuilt easily.</p>
<p>So, a new database, how about a new ORM? Entity Framework 4.1, also known as “<a href="http://www.hanselman.com/blog/SimpleCodeFirstWithEntityFramework4MagicUnicornFeatureCTP4.aspx" target="_blank">magic unicorn edition</a>” is now being used. EF 4.1 “Code First” as it is called, is just awesome. Ditching <a href="http://msdn.microsoft.com/en-us/library/cc982042.aspx" target="_blank">Entity Framework’s EDMX</a> for pure code, now that is right up my alley.</p>
<p>Finally, since I switch to EF 4.1, the current released version of WCF Data Services, well, didn’t work right. You know what did? The <a href="http://blogs.msdn.com/b/astoriateam/archive/2011/10/13/announcing-wcf-data-services-oct-2011-ctp-for-net-4-and-silverlight-4.aspx" target="_blank">WCF Data Services October 2011 CTP</a>, w00t.</p>
<p>Everything you need should be in the new test project (now called RubyODataService, changed from SampleService, though that’s still in the test URLs) thanks to NuGet and my copying of the WCF DS CTP DLLs to the packages directory since there wasn’t a NuGet package for it). </p>
<h3>Pickle</h3>
<p>I love the <a href="https://github.com/ianwhite/pickle" target="_blank">pickle</a> gem. Aside from being authored by <a href="https://github.com/ianwhite" target="_blank">a guy with my last name</a> (no relation), pickle makes Cucumber features so much nicer to read. Throughout development of ruby_odata, I’ve written my own step definitions to do things, essentially cloning what pickle does out-of-the-box, e.g. creating models, asserting against models, etc. I had toyed with getting pickle to work around June of last year, but was having issues. As time passed and experience grew, I finally got it all working. I used it in a few places in new tests, but I hope to do a complete overhaul. My pickle adapter also needs a bit of work since I didn’t put it through all of its paces, and some things need to be added to ruby_odata before it will function as expected. All in all though, it is great to finally have pickle working.</p>
<h2>Conclusion</h2>
<p>I hope that you find the new version of ruby_odata to be useful. In the next version, I hope to further enhance the gem with more of the <a href="http://www.odata.org/developers/protocols/operations" target="_blank">different operations that OData can perform</a>. I’m sure I’ll perform some more housekeeping in the test suite removing my ugly Cucumber steps for nice, clean Pickle steps.</p>
<p>What would you like to see in the new version? Add your suggestions to the <a href="https://github.com/visoft/ruby_odata/issues" target="_blank">issues section on GitHub</a>. I’d also like to know what you think of the API as it stands right now. I’ve essentially been following the OData Silverlight client API syntax (e.g. AddTo&lt;Collection Name&gt; methods, add_link, etc). With the addition of the <code>:first</code> class method, it got me thinking of a bit of a different approach. Not necessarily giving up one for the other, but I think another more Ruby-esq style could co-exist. Anyway, that’s all for now, go forth and do cool things with <a href="https://rubygems.org/gems/ruby_odata" target="_blank">ruby_odata</a>. I’d love to know how you are using the gem. I was excited to find out that ruby_odata was being utilized by the <a href="http://rgovdata.com/" target="_blank">rgovdatablog</a> gem.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.visoftinc.com/2011/12/07/major-ruby-odata-update-v0-1-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby OData Update v0.0.10</title>
		<link>http://blogs.visoftinc.com/2011/09/26/ruby-odata-update-v0-0-10/</link>
		<comments>http://blogs.visoftinc.com/2011/09/26/ruby-odata-update-v0-0-10/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 03:55:18 +0000</pubDate>
		<dc:creator>Damien White</dc:creator>
				<category><![CDATA[OData]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ruby_odata]]></category>
		<category><![CDATA[WCF Data Services]]></category>
		<category><![CDATA[WCF]]></category>
		<guid isPermaLink="false">http://blogs.visoftinc.com/2011/09/26/ruby-odata-update-v0-0-10/</guid>
		<description><![CDATA[I’m happy to announce that today, ruby_odata has continued to move forward by adding additional features and fixing bugs. I skipped an update for v0.0.9, so let’s revisit what was added/fixed back then. The major change was support for self-signed SSL certificates. That addition was courtesy of J.D Mullin. I’m sure you remember his contributions [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.visoftinc.com/wp-content/uploads/2011/09/OData_logo_MS_small.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 10px 12px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="OData_logo_MS_small" border="0" alt="OData_logo_MS_small" align="right" src="http://blogs.visoftinc.com/wp-content/uploads/2011/09/OData_logo_MS_small_thumb.png" width="300" height="37" /></a>I’m happy to announce that today, <a href="http://github.com/visoft/ruby_odata" target="_blank">ruby_odata</a> has continued to move forward by adding additional features and fixing bugs. </p>
<p>I skipped an update for v0.0.9, so let’s revisit what was added/fixed back then. The major change was support for self-signed SSL certificates. That addition was courtesy of <a href="http://jdmullin.blogspot.com/" target="_blank">J.D Mullin</a>. I’m sure you remember his contributions <a href="http://bit.ly/ruby_odata008" target="_blank">back in v0.0.8</a> when he added Basic HTTP Authentication. Aside from J.D.’s contributions, the library was refactored to only make one call to the service for building classes and collections. Finally, a few bug fixes wrapped up the release.</p>
<p>Now onto v0.0.10. A lot of changes were implemented in this release that ended up allowing for wider support for ruby_odata. Thanks to input from Michael Koegel (<a href="http://twitter.com/#!/konfusius" target="_blank">@konfusius</a>), Alvaro Tejada (<a href="http://twitter.com/#!/blag" target="_blank">@Blag</a>), Ingo Sauerzapf (<a href="http://twitter.com/#!/IngoS11" target="_blank">@IngoS11</a>), and Juergen Schmerder (<a href="http://twitter.com/#!/schmerdy" target="_blank">@schmerdy</a>) (I apologize if I missed anyone!), ruby_odata now supports (at least basic functionality) for <a href="http://help.sap.com/saphelp_gateway20/helpdata/en/2f/d48687c1e14e87915d41e595a4285d/content.htm" target="_blank">SAP NetWeaver GateWay</a>.</p>
<p>Another big change is the initial support for <a href="http://www.odata.org/developers/protocols/atom-format#CustomizingtheRepresentationofanEntry" target="_blank">feed customizations</a>. Properties may not be represented within the &lt;m:properties&gt; collection of an entity. Currently ruby_odata supports SyndicationTitle and SyndicationSummary, but adding the other syndication options should be easy to support. If you can supply me with the metadata and a copy of the output that includes the additional feed customizations, I will be happy to add them (or feel free to fork the project and add them yourself).</p>
<p>Here’s are the complete list of changes for v0.0.10:</p>
<ul>
<li><strong>New Features</strong>
<ul>
<li>Added the ability to pass additional parameters that are appended to the query string for requests </li>
<li>Added initial support for feed customizations (SyndicationTitle and SyndicationSummary) </li>
<li>Enhanced ruby_odata’s awareness of classes based on the metadata instead of relying on results that are returned </li>
</ul>
</li>
<li><strong>Bug Fixes</strong>
<ul>
<li>Fixed issues with nested collections (eager loading) </li>
<li>Handled ArgumentError on the Time.parse for older versions of Ruby; used DateTime.parse instead if Time.parse fails </li>
<li>Removed the camelize method call when building the root URL for collections (reported by mkoegel, issue #3 on github) </li>
<li>Handled building results (classes) where the category element is missing but there is a title element instead (reported by mkoegel, issue #3 on github in the comments) </li>
</ul>
</li>
<li><strong>Other</strong>
<ul>
<li>Change HTTP port to 8989 since 8888 conflicts with the Intel AppStore </li>
<li>Refactored service step for HTTP calls where the service address is defined within the step making it easier to make changes in the future</li>
</ul>
</li>
</ul>
<p>For the next release, I hope to continue to fix issues, <a href="http://odetocode.com/Blogs/scott/archive/2010/07/11/odata-and-ruby.aspx" target="_blank">finally add support for inheritance</a>, add the ability to call a custom WebGet methods added to the service, and hopefully namespacing of entities to limit collisions. Do you have other requests? Add them to the <a href="https://github.com/visoft/ruby_odata/issues" target="_blank">issues list</a> on <a href="http://github.com/" target="_blank">GitHub</a>. The previous Lighthouse site for issues has been closed in favor of using GitHub.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.visoftinc.com/2011/09/26/ruby-odata-update-v0-0-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby OData Update v0.0.8</title>
		<link>http://blogs.visoftinc.com/2011/03/14/ruby-odata-update-v008/</link>
		<comments>http://blogs.visoftinc.com/2011/03/14/ruby-odata-update-v008/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 14:57:26 +0000</pubDate>
		<dc:creator>Damien White</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ruby_odata]]></category>
		<category><![CDATA[WCF Data Services]]></category>
		<category><![CDATA[OData]]></category>
		<category><![CDATA[WCF]]></category>
		<guid isPermaLink="false">http://blogs.visoftinc.com/?p=164</guid>
		<description><![CDATA[It has been WAY too long since an update of ruby_odata was released.  I’m happy to announce that version 0.0.8 was released today.  The biggest change, thanks to J.D. Mullin, is support for Basic HTTP Authentication.  It’s an awesome enhancement and very easy to use.  All you need to do is pass in the username [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.odata.org"><img style="margin: 10px 0px 10px 20px; display: inline; float: right;" title="OData_logo_MS_small" src="http://blogs.visoftinc.com/wp-content/uploads/2011/03/OData_logo_MS_small.png" alt="OData_logo_MS_small" width="300" height="37" align="right" /></a>It has been WAY too long since an update of <a href="http://github.com/visoft/ruby_odata" target="_blank">ruby_odata</a> was released.  I’m happy to announce that version 0.0.8 was released today.  The biggest change, thanks to <a href="http://jdmullin.blogspot.com/" target="_blank">J.D. Mullin</a>, is support for Basic HTTP Authentication.  It’s an awesome enhancement and very easy to use.  All you need to do is pass in the username and password as constructor arguments when instantiating a service like so:</p>
<pre class="brush: ruby;">require 'lib/ruby_odata'
svc = OData::Service.new "http://127.0.0.1:8888/SampleService/Entities.svc", { :username =&gt; "bob", :password=&gt; "12345" }</pre>
<p>In addition to the big change by <a href="http://twitter.com/#!/jdmullin" target="_blank">@jdmullin</a>, the following changes are apart of the new version:</p>
<ul>
<li>Support for <a href="http://www.odata.org/developers/protocols/atom-format#PrimitiveTypes" target="_blank">nullable primitive types</a> being returned from an <a href="http://www.odata.org/" target="_blank">OData</a> service.</li>
<li>A change in ActiveSupport 3.0.x broke additions in ruby_odata when you associate a previously saved entity.  This has been corrected, and ActiveSupport 2.3.x (tested 2.3.11) and 3.0.x (tested 3.0.5) are now supported. </li>
<li>Ruby 1.9.2 is now supported.</li>
</ul>
<p>Other “backend” type enhancements were added:</p>
<ul>
<li>Removed Jeweler for releasing gems</li>
<li>Moved to bundler</li>
<li>Updated README to reflect new changes</li>
<li>Updated DB management so that testers aren’t required to move files around</li>
<li>Fixed gemspec to list the development gems</li>
<li>Developers can just do a “bundle install” to get all the required gems</li>
</ul>
<p>One interesting thing that I found while testing is that Ruby 1.9.2 is much faster when running <a href="http://cukes.info" target="_blank">Cucumber</a> tests on Windows.  I was using Ruby 1.8.7-p330 vs 1.9.2-p180 on Windows (<a href="http://rubyinstaller.org/" target="_blank">RubyInstaller</a> rocks!).  Here’s a snapshot:</p>
<p><a href="http://blogs.visoftinc.com/wp-content/uploads/2011/03/CucumberRubyVersionComparison.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="CucumberRubyVersionComparison" src="http://blogs.visoftinc.com/wp-content/uploads/2011/03/CucumberRubyVersionComparison_thumb.png" border="0" alt="CucumberRubyVersionComparison" width="524" height="204" /></a></p>
<p>Note there is a bit of a problem using Ruby 1.9.2 w/ Cucumber on Windows.  The problem is that when using bundler or “gem install,” the <a href="http://rubygems.org/gems/json" target="_blank">json gem</a> gets installed as the x86-mingw32 version.  Running cucumber on Windows with Ruby 1.9.2 (using the incorrectly compiled json gem) yields a msvcrt-ruby18.dll error.  The way I fixed the error was to install the <a href="https://github.com/oneclick/rubyinstaller/wiki/Development-Kit" target="_blank">RubyInstaller DevKit</a>, and then reinstall the gem “correctly” using:</p>
<pre class="brush: bash;">gem uninstall json
gem install json --platform=ruby -v 1.4.6</pre>
<p>What we are doing is uninstalling the incorrect copy of the json gem and then installing v1.4.6 of json using the &#8211;platform=ruby flag which will involve the DevKit to compile the gem for us.  Note that the json gem version required by <a href="http://rubygems.org/gems/cucumber" target="_blank">Cucumber 0.10.0</a> is ~&gt; 1.4.6, and there is a new version out, so the -v 1.4.6 forces the correct one.  Found the <a href="http://stackoverflow.com/questions/2167992/problem-with-ruby-on-rails-on-windowsmsvcrt-ruby18-dll-error-newbie-questions/4777585#4777585" target="_blank">solution on StackOverflow</a>,  but it seems that there should be a better way to solve this, perhaps with <a href="http://gembundler.com/man/bundle-config.1.html" target="_blank">bundle-config</a>?</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.visoftinc.com/2011/03/14/ruby-odata-update-v008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Data Access and Silverlight 4</title>
		<link>http://blogs.visoftinc.com/2010/12/20/data-access-and-silverlight-4/</link>
		<comments>http://blogs.visoftinc.com/2010/12/20/data-access-and-silverlight-4/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 01:05:50 +0000</pubDate>
		<dc:creator>Damien White</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[WCF Data Services]]></category>
		<category><![CDATA[WCF RIA Services]]></category>
		<category><![CDATA[OData]]></category>
		<guid isPermaLink="false">http://blogs.visoftinc.com/?p=156</guid>
		<description><![CDATA[You’ve decided to create a new business application (meaning some n-tier application) using Silverlight as the frontend.&#160; Is Silverlight the best choice?&#160; That’s a debate for another post…&#160; Anyway, now it comes to deciding on a data access strategy, which one do you choose?&#160; Well this is one of those things where there is no [...]]]></description>
			<content:encoded><![CDATA[<p>You’ve decided to create a new business application (meaning some n-tier application) using Silverlight as the frontend.&#160; Is <a href="http://encosia.com/2009/09/14/is-silverlight-the-new-webforms/" target="_blank">Silverlight the best choice</a>?&#160; That’s a debate for another post…&#160; Anyway, now it comes to deciding on a data access strategy, which one do you choose?&#160; Well this is one of those things where there is no clear winner.&#160; To make a choice, <a href="http://wildermuth.com/" target="_blank">Shawn Wildermuth</a> has a great post on the “<a href="http://wildermuth.com/2010/07/08/State_of_Data_Access_in_Silverlight_4" target="_blank">State of Data Access in Silverlight 4</a>.”&#160; Looking at his awesome chart comparing plain WCF, <a href="http://msdn.microsoft.com/en-us/library/cc668792(VS.100).aspx" target="_blank">WCF Data Services</a>, and WCF RIA Services, you’ll see that some of the things on the “Cons” side for all of the approaches could be a deal breaker.&#160; So which one should you choose?&#160; Let me take you through a deliberation that I was involved in recently when forced to make this decision.&#160; There is no right answer here (as with most interesting topics), but I would be interested in your feelings on the topic.&#160; Let’s get started…</p>
<h2>Initial Breakdown</h2>
<p>Given the three strategies that Shawn had identified, we had pretty much focused on just WCF Data Services and WCF RIA Services.&#160; Plain old WCF services are useful for a lot of things, but they aren’t very flexible on their own.&#160; Things like client-side shaping, sorting, filtering or paging are rough, plus I don’t see the value in writing boilerplate service code for CRUD operations.&#160; I suppose you could use something like a T4 template for that, but for “standard” web services the thing I really don’t like is SOAP.&#160; I won’t wax poetic about how REST makes so much more sense than SOAP, but if you are interested, you should check out <a href="http://www.amazon.com/gp/product/0596519206?ie=UTF8&amp;tag=visincblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0596519206">RESTful .NET: Build and Consume RESTful Web Services with .NET 3.5</a> by Jon Flanders, it’s a fantastic book.&#160; Sure, you could have a standard WCF Service using REST instead of SOAP, but I don’t believe that you can generate a proxy against a WCF REST service (I don’t mind WebClient/HttpWebRequest code).&#160; That isn’t a deal breaker, but it is when writing a lot of code against a lot of objects.&#160;&#160; We decided that standard WCF just wasn’t the easiest option for the lion’s share of the work.</p>
<p>So that leaves us with WCF Data Services or WCF RIA Services.&#160; For a previous project we had discounted using WCF RIA Services for the majority of the data access (though, we did use it for user roles and such).&#160; Trying to go into a new project with an open mind, we thought we should dig a little deeper into RIA, after all, it “seems” to be the approach that you should use for a business application as you’ll see.</p>
<p><span id="more-156"></span><br />
<h2>WCF RIA Services Overview</h2>
<p>So you’re building a “Business Application,” right?&#160; Well I guess a good place to start would be <strong>File &gt;&gt; New Project &gt;&gt; Silverlight Business Application</strong>, right?&#160; Well this <a href="http://msdn.microsoft.com/en-us/library/ee707360(v=VS.91).aspx" target="_blank">assumes some things</a>, like that you want to use things like Silverlight Navigation (yes, please), controls for user login and registration (partially ok, but we’re using Windows Authentication and don’t need registration code), and it assumes that you want to use RIA Services (maybe, but you wouldn’t be reading this post if this was clear-cut answer).&#160; I like the <a href="http://msdn.microsoft.com/en-us/library/ee707344(v=VS.91).aspx" target="_blank">concept of RIA Services</a> very much, but the implementation has some fundamental flaws.&#160; Let’s start with a couple of pros that RIA provides where I see real value:</p>
<blockquote><h3>Validation</h3>
<p>Who likes validation code?&#160; Hmmm, no hands raised?&#160; RIA’s <a href="http://www.nikhilk.net/RIA-Services-Validation.aspx" target="_blank">validation seems fantastic</a> (at least on paper; I haven’t tried all of them in practice).&#160; Having validation code that is shared between the client and server is cool and it’s a nice addition to Silverlight.&#160; This is really the single compelling reason behind using RIA Services for me.</p>
<h3>Sharing Code</h3>
<p>Sometimes there is a disconnect between your entity model and the code you want to expose to the client.&#160; For example, let’s say you have a Person object that has a First and Last Name.&#160; Well, you want to expose a property called DisplayName to the client, which joins the First and Last Name.&#160; With RIA, the DisplayName property can be added on the server and Silverlight will see it.&#160; With something like WCF Data Services, you would need to augment the Person class on the Silverlight side, where the server knows nothing about this property (Is that a big deal in this example?&#160; Not really).</p>
</blockquote>
<p><a href="http://wildermuth.com/2010/07/08/State_of_Data_Access_in_Silverlight_4" target="_blank">Shawn’s post</a> lists more than discussed here, but those two really stand out as useful to me.&#160; I want to embrace WCF RIA Services, but a few of the cons really rub me the wrong way.</p>
<blockquote><h3>Model and Service Disconnect</h3>
<p>Referring to <a href="http://wildermuth.com/2010/07/08/State_of_Data_Access_in_Silverlight_4" target="_blank">Shawn’s post</a>, the very first con is “Entity Changes Don’t Cascade to Contract.”&#160;&#160; What does this mean?&#160; Let’s say you are incrementally building an app for managing products.&#160; You start with a very simple model with only one entity exposed, “Product.”&#160; You add the Products to your model, and you expose this over RIA Services using the wizard (listed as a pro on <a href="http://wildermuth.com/2010/07/08/State_of_Data_Access_in_Silverlight_4" target="_blank">Shawn’s post</a>, but wizards aren’t always a blessing as you’ll see).&#160; Anyway, so far so good.&#160; You continue your development, and you find out you need to add a “Category” entity to your model.&#160; Assuming you’re using Entity Framework, you update your model from the database (good tooling), and then you try to expose the entity over your RIA Service.&#160; Ummm…&#160; You try clicking and right-clicking all over looking for something like “Update RIA Service from Model” only to find that it <a href="http://www.sadtrombone.com/" target="_blank">doesn’t exist</a>.</p>
<p>Having a disconnect between the model and the service is a giant red flag for errors on a team.&#160; Your model can end up looking totally different than the objects you are passing over the wire, resulting in all sorts of fun errors.&#160; There are workarounds for the issue, for example <a href="http://www.wcfriaservices.net/Blog/post/How-to-setup-your-DomainService-using-partial-classes-for-easy-maintenance.aspx" target="_blank">using a partial service class for each entity</a>, or <a href="http://blog.davidyack.com/journal/2009/5/20/update-net-ria-services-domain-service-from-model.html" target="_blank">manually copying and pasting code from a temporary service into your actual service</a>.&#160; You can get over the con of not having tooling, but neither option is really great (IMHO).</p>
<h3>No Eager Loading Support</h3>
<p>I was most shocked to find this out, since the proxies for WCF Data Services and WCF RIA Services look similar.&#160; With RIA, when you are in Silverlight (say a ViewModel or Repository) you cannot dictate what data you want.&#160; Let’s say you have a Person object, and each Person has 1 to many Address objects.&#160; On the client, you want to get and display a property found on the Address object (like City or something).&#160; Well, the client can’t eager load the Person’s Addresses.&#160; With WCF Data Services, you can add an .Expand(“Address”) to your query that you send in order to eagerly load the Address for a Person.&#160; This doesn’t exist with RIA though.&#160; The workaround is to perform an .Include(“Address”) in your service method that gets the list of People.&#160; However, this really isn’t a workaround.&#160; As a consumer of a service (Silverlight or otherwise), I want to be able to dictate what I need, not have the server force the “worst case scenario” down to me.&#160; Of course you could have two methods, like GetPeople() and GetPeopleWithAddresses(), etc., but yuck.</p>
<h3>Generated Code</h3>
<p>This isn’t listed in Shawn’s list, but I’ve bumped into issues with the “Generated Code” folder in my Silverlight projects.&#160; WCF RIA Services generates it’s client-side code when you build your solution.&#160; This is super fragile.&#160; What is wrong with Service References?&#160; I’d like to have the option to break my client when I feel like it (Update Service Reference), but I don’t get the choice with RIA.&#160; Build your solution, and boom all the changes are pulled down whether you are ready or not.</p>
</blockquote>
<h2>WCF Data Services Overview</h2>
<p>Full disclosure, I <strong>LOVE</strong> WCF Data Services.&#160; Does it have some shortcomings?&#160; Sure, but it’s quite amazing.&#160; I have been using WCF Data Services through all of it’s names (code-name Astoria, ADO.NET Data Services, and now WCF Data Services).&#160; I’ve used it before the output was known as <a href="http://www.odata.org/" target="_blank">OData</a>, etc.&#160; In short, I’m a huge fan of the strategy.&#160; My love of WCF Data Services comes from the fact that they are REST based and can be consumed by just about anything (shameless plug for <a href="http://github.com/visoft/ruby_odata" target="_blank">ruby_odata</a>; <a href="http://blogs.visoftinc.com/archive/2010/06/12/Introducing-a-Ruby-OData-Client-Library.aspx">more info here</a>).&#160; I also like the simplicity of exposing your data model over HTTP.&#160; IQueryable&lt;T&gt; collections, that I can shape on the client and I don’t have to code specific methods for, makes all the sense in the world to me.&#160; As you know I’ve <a href="http://bit.ly/bfEkgT" target="_blank">fallen in love with Ruby on Rails</a>, but WCF Data Services is THE thing that I miss when writing a Rails app.&#160; All I’m saying is that my views may be a little skewed.</p>
<p>Having used WCF Data Services for so long, I’m pretty familiar with the good and the bad.&#160; The only two things that are lacking are the two “pros” found in the WCF RIA Services discussion found above.&#160; Really though, WCF Data Services serve all spaces and isn’t specific to “Silverlight” or RIA Applications.&#160; You can do validations with WCF Data Services just fine (e.g. <a href="http://msdn.microsoft.com/en-us/library/dd744842.aspx" target="_blank">QueryInterceptors and ChangeInterceptors</a>), but these are limited to the server.&#160; It makes perfect sense though.&#160; How could the WCF Data Services team integrate client and server validation into one when the range of clients is so broad?&#160; The wide reach of WCF Data Services is what makes them so useful.</p>
<h3>Conclusions</h3>
<p>After deliberating for hours, we decided to stick with WCF Data Services for the lion’s share of our development.&#160; This decision was made simply because none of the WCF Data Services cons were deal-breakers for us, while the cons with WCF RIA Services were harder to swallow.&#160; Again, that doesn’t mean we aren’t going to use pieces here and there (like RIA for roles and such), but we felt we needed a “default direction.”&#160; What are your feelings on this?</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.visoftinc.com/2010/12/20/data-access-and-silverlight-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introducing a Ruby OData Client Library</title>
		<link>http://blogs.visoftinc.com/2010/06/12/introducing-a-ruby-odata-client-library/</link>
		<comments>http://blogs.visoftinc.com/2010/06/12/introducing-a-ruby-odata-client-library/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 04:37:28 +0000</pubDate>
		<dc:creator>Damien White</dc:creator>
				<category><![CDATA[OData]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ruby_odata]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[WCF Data Services]]></category>
		<category><![CDATA[Web Services]]></category>
		<guid isPermaLink="false">/archive/2010/06/12/Introducing-a-Ruby-OData-Client-Library.aspx</guid>
		<description><![CDATA[Ever since the ADO.NET team started development on Astoria (pre-release), I have loved the concept.&#160; Since its release (it was called ADO.NET Data Services and is now WCF Data Services), I’ve used it a ton (you may remember the example from this post).&#160; Back at MIX10, Microsoft announced a commitment to the Open Data Protocol [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.odata.org/"><img style="border-right-width: 0px; margin: 20px 10px 20px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="OData_logo_MS_small" border="0" alt="OData_logo_MS_small" align="right" src="http://blogs.visoftinc.com/wp-content/uploads/OData_logo_MS_small.png" width="240" height="29" /></a> Ever since the ADO.NET team started development on Astoria (pre-release), I have loved the concept.&#160; Since its release (it was called ADO.NET Data Services and is now WCF Data Services), I’ve used it a ton (you may remember the example from <a href="http://blogs.visoftinc.com/archive/2009/05/27/ASP.NET-4.0-AJAX-Preview-4-Data-Binding.aspx">this post</a>).&#160; Back at MIX10, Microsoft announced a commitment to the <a href="http://www.odata.org/" target="_blank">Open Data Protocol</a> (<a href="http://www.odata.org/" target="_blank">OData</a>).&#160; <a href="http://msdn.microsoft.com/en-us/library/cc668792(VS.100).aspx" target="_blank">WCF Data Services</a> enables you to create services that use OData to expose and consume data, both with .NET 4 and .NET 3.5 SP1.&#160; OData services are very powerful and there are quite a few <a href="http://www.odata.org/producers" target="_blank">live producers</a> such as <a href="http://odata.netflix.com/Catalog/" target="_blank">Netflix</a> and <a href="http://www.nerddinner.com/Services/OData.svc/" target="_blank">Nerd Dinner</a>.</p>
<p>OData is so powerful because it’s REST based and you can access the services from just about everywhere, including just a simple URL.&#160; For example, using the Netflix OData service to access the best movie ever made by title: <a href="http://odata.netflix.com/Catalog/Titles?$filter=Name eq 'Office Space'">http://odata.netflix.com/Catalog/Titles?$filter=Name eq &#8216;Office Space&#8217;</a>.&#160; Pretty simple.&#160; Of course accessing things solely based on URLs in code isn’t the best, and hence the reason for my post.</p>
<h2>Client Libraries</h2>
<p>When using OData, it’s convenient to utilize an SDK to access the services.&#160; For example, in <a href="http://msdn.microsoft.com/en-us/library/cc838234(VS.96).aspx" target="_blank">Silverlight</a> you can access <a href="http://msdn.microsoft.com/en-us/library/ff650916(v=VS.96).aspx" target="_blank">OData services using LINQ</a>.&#160; There’s also a fantastic <a href="http://www.asp.net/ajaxLibrary/odata.ashx" target="_blank">AJAX Library</a> (which I used in a <a href="http://blogs.visoftinc.com/archive/2009/05/27/ASP.NET-4.0-AJAX-Preview-4-Data-Binding.aspx" target="_blank">previous post</a>).&#160; There are SDKs for <a href="http://odataphp.codeplex.com/" target="_blank">PHP</a>, <a href="http://odataobjc.codeplex.com/" target="_blank">Objective-C</a>, and many others, but there was one missing that I wanted to use… Ruby.&#160; I am assuming this comes as no surprise given my new found <a href="http://blogs.visoftinc.com/category/Ruby.aspx">love for Ruby</a>.</p>
<p><span id="more-71"></span><br />
<h2>Introducing ruby_odata</h2>
<p>I’ve been messing around with Ruby enough to start working on my first Ruby open-source project.&#160; It’s always good to contribute to the open-source community.&#160; While I’m not a seasoned Ruby developer, I figure this is a good project to start on.&#160; Now I can code stuff in Ruby and consume WCF services I have written in the past and will continue to write in the future (that is until there is “OData on <a href="http://rubyonrails.org/" target="_blank">Rails</a>,” perhaps an idea for a new project?).</p>
<p>The source code, like all good Ruby code, is <a href="http://github.com/visoft/ruby_odata" target="_blank">hosted on GitHub</a>.&#160; The <a href="http://github.com/visoft/ruby_odata/blob/master/README.rdoc" target="_blank">README</a> will give you a good idea of how to use the library.&#160; Currently (as of 06/12/2010) there are limitations, such as not being able to batch changes (like multiple Adds), but no worries, I’m working on adding them (actually, I cut three releases today, adding extra querying abilities).&#160; That said, it is functional enough to use for most operations right now.&#160; Once it’s been better tested in the real world and I’ve been able to incorporate most if not all of the OData functionality, I will be versioning more responsibly.&#160; Right now, because I’m adding functionality quickly and I want others to be able to use it, you’ll be seeing lots of updates so the version number will be a bit jumpy for a while.</p>
<h2>The Genesis of ruby_odata</h2>
<p>I started writing ruby_odata in order to interface with my database via services so I could do testing in Ruby and create objects from within the tests that I could use in my ASP.NET MVC application.&#160; I wrote about BDD testing in <a href="http://blogs.visoftinc.com/archive/2010/06/10/Behavior-Driven-Development-(BDD)-with-Cucumber-and-ASP.NET-MVC.aspx">an earlier post</a> where I fixed the speed of running the tests using Cucumber with <a href="http://github.com/tenderlove/mechanize" target="_blank">Mechanize</a>.&#160; Another area missing in .NET is the ability to automatically generate objects to test against like you can with <a href="http://github.com/ianwhite/pickle" target="_blank">Ian White’s Pickle</a>.&#160;&#160; <a href="http://github.com/ianwhite/pickle" target="_blank">Pickle</a> interacts nicely with factories and your database to create objects for tests.&#160; For example, a step like: <span style="font-family: courier new">Given a user exists with name: &quot;Damien&quot; </span>will automatically create a new user in the test database.&#160; This works dandy in the Ruby world (with <a href="http://rails.rubyonrails.org/classes/ActiveRecord/Base.html" target="_blank">ActiveRecord</a> for example), but against something like Entity Framework, not so much.&#160; With <a href="http://github.com/visoft/ruby_odata" target="_blank">ruby_odata</a> however, this is something that could work in a similar way. (Yet another idea for a project, a Pickle adapter that utilizes ruby_odata.&#160; Man, so many ideas, so little time.)</p>
<h2>Usage Overview</h2>
<p>The library is pretty straightforward to use.&#160; At the heart is the <strong>OData::Service</strong>.&#160; This is the root object that drives all of your operations against the services.&#160;&#160; Once you instantiate the <strong>OData::Service</strong>, dynamic methods based on the OData service’s collections are available to call.&#160; For example, using the <a href="http://odata.netflix.com/Catalog/" target="_blank">Netflix OData service</a>, we can see there is a collection called “Titles.”&#160; Within ruby_odata, the <strong>OData::Service </strong>will respond to a “Titles” method:</p>
<pre class="brush: ruby;">svc = OData::Service.new &quot;http://odata.netflix.com/Catalog/&quot;
puts &quot;Responds to Titles? #{svc.respond_to? :Titles}&quot; # =&gt; Responds to Titles? true</pre>
<p>
  <br />So, just by looking at the collections on the <a href="http://odata.netflix.com/Catalog/" target="_blank">main service page</a>, or <a href="http://odata.netflix.com/Catalog/$metadata" target="_blank">metadata page</a>, you can see what you can query.&#160; Here’s an example of querying for a movie (like we did earlier with a straight up URL):</p>
<p></p>
<pre class="brush: ruby;">svc.Titles.filter(&quot;Name eq 'Office Space'&quot;)
movie = svc.execute
# Now we can access properties of the Title (defined in the service metadata)
puts &quot;Average Rating: #{movie.AverageRating}&quot;
puts &quot;Release Year: #{movie.ReleaseYear}&quot;
puts &quot;URL: #{movie.Url}&quot;
# =&gt; Average Rating: 4.2
# =&gt; Release Year: 1999
# =&gt; URL: http://www.netflix.com/Movie/Office_Space/20358351</pre>
<p>Pretty cool, huh?</p>
<h2>The Basics</h2>
<p>There is a simple pattern for using the library.&#160; For queries, you call a collection on the service (like you saw with <strong>Titles</strong> in the Netflix example above), and that returns an <strong>OData::QueryBuilder</strong> object to you in which you can fluently add options like <strong>filter</strong> or <strong>expand</strong>.&#160; If you use multiple calls to filter, it will perform an “AND” query against the service, and multiple expand calls will yield multiple items being expanded.&#160; You can also mix the calls, like <strong>.filter(…).expand(…)</strong>.&#160; Once you are done building a query, you call the <strong>execute</strong> method on the service.&#160; The result of the execute is either a single entity or a collection of the entities based on your query.</p>
<p>In order to add, update, or delete, you need to call the appropriate method on the <strong>OData::Service</strong>.&#160; To add, you would use the dynamic method <strong>AddTo&lt;Collection Name&gt;</strong>, where the &lt;Collection Name&gt; is the name of the collection on the service (as defined by the metadata).&#160; To update, you would use <strong>update_object,</strong> passing in the updated version of the object.&#160; Finally, to delete, you would use <strong>delete_object</strong>, passing the object to delete.&#160; Once you do one of these operations, you need to persist the change using the <strong>save_changes</strong> method on the <strong>OData::Service</strong>.&#160; Currently, you need to call save_changes after each operation in order to persist the data.&#160; In the future you will be able to batch operations instead of persisting them one at a time.</p>
<h2>More Examples</h2>
<p>For more examples, download the <a href="http://github.com/visoft/ruby_odata" target="_blank">source code</a> from GitHub and setup the testing environment (instructions for setting up the test environment are located in the <a href="http://github.com/visoft/ruby_odata/blob/master/README.rdoc" target="_blank">README</a>).&#160; When you setup the test environment, you can follow along with the samples as shown in the <a href="http://github.com/visoft/ruby_odata/blob/master/README.rdoc" target="_blank">README</a>.&#160; There are examples for all the CRUD operations.</p>
<h2>Conclusion</h2>
<p>There you have it, an OData library for Ruby.&#160; I am very excited by the potential of <a href="http://www.odata.org/" target="_blank">OData</a>, and having the ability to consume the services easily within Ruby is extremely useful.&#160; I hope you find the library helpful.&#160; The current version is a bit of a work in progress since everything isn’t fully supported yet, but I will continue to work on the project.&#160; You can get involved by checking out the resources for the project:</p>
<ul>
<li>Source Code (hosted on GitHub): <a title="http://github.com/visoft/ruby_odata" href="http://github.com/visoft/ruby_odata">http://github.com/visoft/ruby_odata</a> </li>
<li>Documentation (hosted on rdoc.info): <a title="http://rdoc.info/projects/visoft/ruby_odata" href="http://rdoc.info/projects/visoft/ruby_odata">http://rdoc.info/projects/visoft/ruby_odata</a> </li>
<li>Issue tracking (hosted on GitHub): <a title="https://github.com/visoft/ruby_odata/issues" href="https://github.com/visoft/ruby_odata/issues">https://github.com/visoft/ruby_odata/issues</a></li>
<li>Wiki (hosted on GitHub): <a title="http://wiki.github.com/visoft/ruby_odata/" href="http://wiki.github.com/visoft/ruby_odata/">http://wiki.github.com/visoft/ruby_odata/</a> </li>
</ul>
<p>If you just want to start using it without the source code, you can install ruby_odata as a <a href="http://rubygems.org/gems/ruby_odata" target="_blank">gem from RubyGems.org</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.visoftinc.com/2010/06/12/introducing-a-ruby-odata-client-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET AJAX 4.0 and the ScriptManager Control</title>
		<link>http://blogs.visoftinc.com/2009/06/01/asp-net-ajax-4-0-and-the-scriptmanager-control/</link>
		<comments>http://blogs.visoftinc.com/2009/06/01/asp-net-ajax-4-0-and-the-scriptmanager-control/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 19:15:48 +0000</pubDate>
		<dc:creator>Damien White</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[WCF Data Services]]></category>
		<category><![CDATA[ASP.NET AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">/archive/2009/06/01/ASP.NET-AJAX-4.0-and-the-ScriptManager-Control.aspx</guid>
		<description><![CDATA[I have been using ASP.NET AJAX 4.0 quite a bit lately, as I’m sure most of you are aware from my recent posts.&#160; In those posts, I used standard HTML script references to show that ASP.NET AJAX is not reliant upon ASP.NET.&#160; I realize that many of you are in fact using ASP.NET, and today [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-right-width: 0px; margin: 0px 0px 15px 15px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Puzzle Pieces" border="0" alt="Puzzle Pieces" align="right" src="http://blogs.visoftinc.com/wp-content/uploads/PuzzlePieces_1.jpg" width="136" height="200" /> I have been using ASP.NET AJAX 4.0 quite a bit lately, as I’m sure most of you are aware from my recent posts.&#160; In those posts, I used standard HTML script references to show that ASP.NET AJAX is not reliant upon ASP.NET.&#160; I realize that many of you are in fact using ASP.NET, and today we will take a look at using the ScriptManager. </p>
<p>First we’ll look at using the Preview 4 scripts within an ASP.NET 3.5 application (with the ScriptManager of course) as well as using client templates and ADO.NET Data Services with the ScriptManager in ASP.NET 4.0 (Beta 1).&#160; After that, we’ll take a closer look at some of the new features of the ScriptManager in ASP.NET 4.0. </p>
<h2>Preview 4 and the ASP.NET 3.5 ScriptManager</h2>
<p>In my posts on ASP.NET AJAX 4.0 so far, I used standard HTML script references (as stated earlier).&#160; However, what if you wanted to incorporate the new ASP.NET AJAX 4.0 scripts with a ScriptManager.&#160; I tried this in a recent ASP.NET 3.5 SP1 project, and ran into some issues getting it all to work out.&#160; Thanks to <a href="http://weblogs.asp.net/wallym/archive/2009/03/17/asp-net-4-0-ajax-preview-release-4-setup.aspx" target="_blank">this blog</a> (and <a href="http://weblogs.asp.net/bleroy/" target="_blank">Bertrand LeRoy</a>), I found the solution.</p>
<pre class="brush: xml;">&lt;asp:scriptmanager id=&quot;sm&quot; runat=&quot;server&quot;&gt;
    &lt;scripts&gt;
        &lt;asp:scriptreference scriptmode=&quot;Inherit&quot; name=&quot;MicrosoftAjax.js&quot; path=&quot;~/scripts/MicrosoftAjax.js&quot; /&gt;
        &lt;asp:scriptreference scriptmode=&quot;Inherit&quot; path=&quot;~/scripts/MicrosoftAjaxAdoNet.js&quot; /&gt;
        &lt;asp:scriptreference scriptmode=&quot;Inherit&quot; path=&quot;~/scripts/MicrosoftAjaxTemplates.js&quot; /&gt;
    &lt;/scripts&gt;
&lt;/asp:scriptmanager&gt;</pre>
<p><span id="more-24"></span></p>
<h2>Client Templates and ASP.NET 4.0 ScriptManager</h2>
<p>If you are using Visual Studio 2010 (currently in Beta 1) and you want to use client templates (e.g. DataView) or ADO.NET Data Services, you may think you can just add a ScriptManager to the page (at least I initially did) and everything will work.&#160; This isn’t the case.&#160; These are new features of ASP.NET AJAX , so you need to add them as ScriptReferences.&#160; I’m not sure if this will change for the release, but in an effort to keep the size down, I’m thinking this may be the way it stays.&#160; Not that big of a deal, just something to be aware of.</p>
<pre class="brush: xml;">&lt;asp:ScriptManager ID=&quot;sm&quot; runat=&quot;server&quot;&gt;
    &lt;Scripts&gt;
        &lt;asp:ScriptReference Name=&quot;MicrosoftAjaxTemplates.js&quot; /&gt;
        &lt;asp:ScriptReference Name=&quot;MicrosoftAjaxAdoNet.js&quot; /&gt;
    &lt;/Scripts&gt;
&lt;/asp:ScriptManager&gt;</pre>
<h2>ASP.NET 4.0 ScriptManager &#8211; Activating Elements Declaratively </h2>
<p>In my previous posts, you’ve seen both declarative and imperative examples using ASP.NET AJAX components and controls.&#160; To refresh your memory, let’s look at the “<a href="http://blogs.visoftinc.com/archive/2009/05/27/ASP.NET-4.0-AJAX-Preview-4-Data-Binding.aspx">Simplest Live Binding Example</a>” from my <a href="http://blogs.visoftinc.com/archive/2009/05/27/ASP.NET-4.0-AJAX-Preview-4-Data-Binding.aspx">data binding post</a>.&#160; This snippet uses live binding and client templates (the DataView).&#160; If you need a refresher on the basics of the DataView and using it declaratively, be sure to check out my <a href="http://blogs.visoftinc.com/archive/2009/04/28/ASP.NET-4.0-AJAX-Preview-4-Client-Templates.aspx">client template post</a>.</p>
<pre class="brush: xml;">&lt;body xmlns:sys=&quot;javascript:Sys&quot;
      xmlns:dataview=&quot;javascript:Sys.UI.DataView&quot;
      sys:activate=&quot;simpleForm&quot;&gt;
    &lt;div id=&quot;simpleForm&quot; class=&quot;sys-template&quot;
        sys:attach=&quot;dataview&quot;
         dataview:data=&quot;{{ { name:'' } }}&quot;&gt;
        Name: &lt;input id=&quot;name&quot; type=&quot;text&quot; value=&quot;{binding name}&quot; /&gt;&lt;br /&gt;
        &lt;span id=&quot;nameDisplay&quot;&gt;{binding name}&lt;/span&gt;
    &lt;/div&gt;
&lt;/body&gt;</pre>
<p>One of the keys to getting this to work is to have it activate and bind when the page loads.&#160; In the declarative syntax, this is achieved through the sys:activate attribute found on the body tag.&#160; In some instances, such as working with a content page, you may not have access to the body tag.&#160; In this case the new <strong><em>ClientElementsToActivate</em></strong> property of the ScriptManager and ScriptManagerProxy controls, helps to alleviate this problem.&#160; The <strong><em>ClientElementsToActivate</em></strong> property accepts a comma-delimited list of elements to activate, just like the sys:activate attribute does.&#160; Taking the previous snippet as an example, we can see how using this new property can be used with the ScriptManager (note I have included the ScriptReference since this sample requires the DataView, not because it is needed to use the ClientElementsToActivate property).</p>
<pre class="brush: xml;">&lt;asp:ScriptManager ID=&quot;sm&quot;  runat=&quot;server&quot;
       ClientElementsToActivate=&quot;simpleForm&quot;&gt;
    &lt;Scripts&gt;
        &lt;asp:ScriptReference  Name=&quot;MicrosoftAjaxTemplates.js&quot; /&gt;
    &lt;/Scripts&gt;
&lt;/asp:ScriptManager&gt;
&lt;div id=&quot;simpleForm&quot; class=&quot;sys-template&quot;
    sys:attach=&quot;dataview&quot;
     dataview:data=&quot;{{ { name:'' } }}&quot;&gt;
    ...
&lt;/div&gt;</pre>
<h2>ASP.NET 4.0 ScriptManager – ASP.NET AJAX Enhancements</h2>
<p>A new feature of the ScriptManager in ASP.NET 4.0 is the ability to use only parts of the ASP.NET AJAX Library.&#160; In addition, you can also use the ScriptManager without using <strong>any</strong> of the ASP.NET AJAX framework.&#160; You can now get the benefits from ScriptManager such as support for debug / release modes, localization, script combining, etc, without having to have ASP.NET AJAX scripts rendered by default (as it is now in 3.5).</p>
<p>In ASP.NET 4.0, the default behavior is the same as the current behavior in ASP.NET 3.5, meaning the complete ASP.NET AJAX library is included by default.&#160; Remember from earlier that this does not include MicrosoftAjaxTemplates.js or MicrosoftAjaxAdoNet.js (at least in Beta 1). </p>
<p>The ScriptManager control has a new property, <strong><em>MicrosoftAjaxMode</em></strong>, which allows you to override the default behavior.&#160; The settings available for the <strong><em>MicrosoftAjaxMode</em></strong> are:</p>
<ul>
<li><strong>Enabled</strong> – The default value, all Microsoft AJAX script are included.&#160; This is the same as the current behavior (e.g. ASP.NET 3.5). </li>
<li><strong>Explicit</strong> – This allows you to pick and choose what scripts are referenced.&#160; You need to make sure that you include all scripts that have dependencies on one another. </li>
<li><strong>Disabled</strong> – All the the Microsoft ASP.NET AJAX scripts are disabled and no scripts are referenced automatically. </li>
</ul>
<p>If you use Explicit mode, the following Microsoft AJAX scripts are available for reference:</p>
<ul>
<li>MicrosoftAjaxCore.js </li>
<li>MicrosoftAjaxComponentModel.js </li>
<li>MicrosoftAjaxSerialization.js </li>
<li>MicrosoftAjaxGlobalization.js </li>
<li>MicrosoftAjaxHistory.js </li>
<li>MicrosoftAjaxNetwork.js </li>
<li>MicrosoftAjaxWebServices.js </li>
<li>MicrosoftAjaxApplicationServices.js </li>
<li>MicrosoftAjaxTemplates.js (New for ASP.NET AJAX 4.0) </li>
<li>MicrosoftAjaxAdoNet.js (New for ASP.NET AJAX 4.0) </li>
</ul>
<p>For more information on the new functionality as well as the dependencies for the Microsoft AJAX Library scripts, refer to the <a href="http://www.asp.net/learn/whitepapers/aspnet40/#_Refactoring_the_Microsoft" target="_blank">ASP.NET 4.0 and Visual Studio 2010 Web Development Overview</a> whitepaper.</p>
<h2>More ASP.NET AJAX 4.0 Reading</h2>
<p>If you are interested in ASP.NET AJAX 4.0, and have missed my past posts, be sure to check out:</p>
<ul>
<li><a href="http://blogs.visoftinc.com/archive/2009/04/28/ASP.NET-4.0-AJAX-Preview-4-Client-Templates.aspx">ASP.NET 4.0 AJAX – Preview 4 – Client Templates</a> </li>
<li><a href="http://blogs.visoftinc.com/archive/2009/05/21/ASP.NET-4.0-AJAX-Preview-4-JavaScript-Observer-Pattern.aspx">ASP.NET 4.0 AJAX – Preview 4 – JavaScript Observer Pattern</a> </li>
<li><a href="http://blogs.visoftinc.com/archive/2009/05/27/ASP.NET-4.0-AJAX-Preview-4-Data-Binding.aspx">ASP.NET 4.0 AJAX – Preview 4 – Data Binding</a> </li>
</ul>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d8b75fc6-8b29-4f1e-9bde-5512316506e4" class="wlWriterSmartContent">Technorati Tags: <a href="http://technorati.com/tags/ScriptManager" rel="tag">ScriptManager</a>,<a href="http://technorati.com/tags/ASP.NET" rel="tag">ASP.NET</a>,<a href="http://technorati.com/tags/AJAX" rel="tag">AJAX</a></div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.visoftinc.com/2009/06/01/asp-net-ajax-4-0-and-the-scriptmanager-control/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>ASP.NET 4.0 AJAX &#8211; Preview 4 &#8211; Data Binding</title>
		<link>http://blogs.visoftinc.com/2009/05/27/asp-net-4-0-ajax-preview-4-data-binding/</link>
		<comments>http://blogs.visoftinc.com/2009/05/27/asp-net-4-0-ajax-preview-4-data-binding/#comments</comments>
		<pubDate>Wed, 27 May 2009 10:48:29 +0000</pubDate>
		<dc:creator>Damien White</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WCF Data Services]]></category>
		<category><![CDATA[ASP.NET AJAX]]></category>
		<guid isPermaLink="false">/archive/2009/05/27/ASP.NET-4.0-AJAX-Preview-4-Data-Binding.aspx</guid>
		<description><![CDATA[Throughout the course of my introductory posts on ASP.NET AJAX 4.0, we looked at the new DataView control as well as the Sys.Observer class, which brings the Observer pattern to plain JavaScript objects.  The new ASP.NET AJAX release is very exciting offering powerful new features to take AJAX enabled applications to a new level.  In [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin: 0px 15px 5px 0px; display: inline; border-width: 0px;" title="Laptop" src="http://blogs.visoftinc.com/wp-content/uploads/Laptop.jpg" border="0" alt="Laptop" width="204" height="175" align="left" />Throughout the course of my introductory posts on ASP.NET AJAX 4.0, we looked at the new <a href="http://blogs.visoftinc.com/archive/2009/04/28/ASP.NET-4.0-AJAX-Preview-4-Client-Templates.aspx">DataView control</a> as well as the <a href="http://blogs.visoftinc.com/archive/2009/05/21/ASP.NET-4.0-AJAX-Preview-4-JavaScript-Observer-Pattern.aspx">Sys.Observer class</a>, which brings the Observer pattern to plain JavaScript objects.  The new ASP.NET AJAX release is very exciting offering powerful new features to take AJAX enabled applications to a new level.  In this post, we’ll look at another exciting feature of ASP.NET AJAX 4.0 known as “live bindings.”</p>
<p>You may remember that we looked briefly at live bindings in the <a href="http://blogs.visoftinc.com/archive/2009/04/28/ASP.NET-4.0-AJAX-Preview-4-Client-Templates.aspx">client templates</a> post, but for those examples I used one-way / one-time bindings.  Today, we’ll take a closer look at live bindings and see how two-way live bindings removes the one-way / one-time binding restriction allowing us to update bound elements on our page automatically when the underlying data changes.</p>
<p>Again, in this post, I’ll be using Preview 4 of the ASP.NET AJAX Library, which can be downloaded from <a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24645" target="_blank">CodePlex</a>.  The Preview 4 version can be used in your applications today (e.g. ASP 3.5, HTML).  Keep in mind that these components are still in &#8220;preview&#8221; mode (meaning no Microsoft support), though they are usable at your own risk.  For more information, you can check out the <a href="http://aspnet.codeplex.com/license" target="_blank">license</a> on CodePlex.</p>
<p><span id="more-25"></span></p>
<h2>Source Code</h2>
<p>You can download and run all of the sample code that you find in this post.  The source code contains a Web Site project and uses .NET 3.5 SP1 for the server-side components (e.g. Entity Framework, ADO.NET Data Services) and SQL Server Express 2008.</p>
<p><a href="/wp-content/uploads/DataBindingSamples.zip"><img style="margin: 0px auto 5px; display: block; float: none; border-width: 0px;" title="Download the Source Code - DataBindingSamples.zip " src="http://blogs.visoftinc.com/wp-content/uploads/databindingsamplesDownload.gif" border="0" alt="Download the Source Code - DataBindingSamples.zip " width="404" height="68" /></a></p>
<h2>The Simplest Live Binding Example</h2>
<p>Let’s start with a very simple example of live binding in action.  In the first snippet, we’ll look at binding a very simple client template (the Sys.UI.DataView) using the declarative creation and binding syntax.</p>
<pre class="brush: xml;">&lt;body xmlns:sys="javascript:Sys"
      xmlns:dataview="javascript:Sys.UI.DataView"
      sys:activate="simpleForm"&gt;
    &lt;div id="simpleForm" class="sys-template"
        sys:attach="dataview"
         dataview:data="{{ { name:'' } }}"&gt;
        Name: &lt;input id="name" type="text" value="{binding name}" /&gt;&lt;br /&gt;
        &lt;span id="nameDisplay"&gt;{binding name}&lt;/span&gt;
    &lt;/div&gt;
&lt;/body&gt;</pre>
<p><img style="margin: 10px 0px 0px; display: inline; border-width: 0px;" title="Simple Live Binding" src="http://blogs.visoftinc.com/wp-content/uploads/Simple%20Live%20Binding.gif" border="0" alt="Simple Live Binding" width="216" height="92" align="right" />If you read my <a href="http://blogs.visoftinc.com/archive/2009/04/28/ASP.NET-4.0-AJAX-Preview-4-Client-Templates.aspx">client template post</a>, most of this code should look familiar.  There are a couple of new things in this snippet however.  First, you probably noticed the {binding name}.  This is the live binding syntax.  We’ll look closer at this a bit later, but if you’ve used WPF or Silverlight the syntax should look familiar.  The one other thing that I’ve added to make this work is the dataview:data attribute.  The {{ }} syntax in this attribute simply defines an inline expression, and inside of that, I’ve created an inline JavaScript object, which contains one property ‘name’ and the value is just an empty string (I could have just as easily used null).  The reasoning behind this is that the DataView needs to initially bind data to something, so based on our binding expressions, both the input and span will be initially filled with the empty “name” property.</p>
<p>When you load this page, and enter your name in the textbox, the span will be updated with what you entered in the textbox after you tab away from it.  You can see this in action in the clip playing off to the right.</p>
<h2>Using Sys.Binding Imperatively</h2>
<p>In the last example, we used a DataView along with the binding markup.  The binding markup {binding propertyName} and {{ propertyName }} can only be used inside client templates (the DataView).  What if you didn’t want to use a DataView for something like that last example?  Well it’s possible, thanks to the way that binding is handled in ASP.NET AJAX.  The binding markup maps back to the component Sys.Binding, which in turn uses <a href="http://blogs.visoftinc.com/archive/2009/05/21/ASP.NET-4.0-AJAX-Preview-4-JavaScript-Observer-Pattern.aspx">Sys.Observer</a>.  We can harness the power of Sys.Binding directly if needed.  Let’s see how we would accomplish the same example as before, but this time using Sys.Binding directly.  We can do this declaratively (like the DataView example from above) or imperatively using JavaScript.  First, we’ll look at the imperative code:</p>
<pre class="brush: xml;">&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
        &lt;!-- Script references removed for brevity --&gt;
        &lt;script type="text/javascript"&gt;
        Sys.Application.add_init(function() {
            $create(Sys.Binding,
            {
                source: $get('name'),
                path: "value",
                target: $get('nameDisplay'),
                targetProperty: "innerHTML"
            });
        });
    &lt;/script&gt;
  &lt;/head&gt;
&lt;body&gt;
    &lt;div id="simpleForm"&gt;
        Name: &lt;input id="name" type="text" /&gt;&lt;br /&gt;
        &lt;span id="nameDisplay"&gt;&lt;/span&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>You’ll notice there isn’t much going on in the HTML this time since this isn’t declaratively bound.</p>
<p>Looking at the JavaScript block, I’m using the $create shortcut in order to wire up the Sys.Binding component.  Since this is a component and not a control like the DataView, the only parameters that need to be passed to $create is the type (Sys.Binding) and properties for the Sys.Binding component (a JavaScript object).  The $create call is simply creating an association between the textbox (input) and the span.  Again, the results of this code are exactly the same as the initial example that we looked at.</p>
<p>Let’s take a closer look at the properties being set in the last example:</p>
<table border="1" cellspacing="0" cellpadding="2" width="398">
<tbody>
<tr>
<td width="112" valign="top"><strong>source</strong></td>
<td width="284" valign="top">
<p>The source object (the textbox in our case).</p>
<p>Note: This is using $get in order to access the element by its Id.</p>
</td>
</tr>
<tr>
<td width="114" valign="top"><strong>path</strong></td>
<td width="282" valign="top">
<p>The property name or path to the source property.  This is the property value that will be sent to the target (the value property of the textbox in our case).</p>
<p>I would have expected this to be called sourceProperty since there is a targetProperty, but this follows the <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.path(VS.85).aspx" target="_blank">WPF convention</a>.</p>
</td>
</tr>
<tr>
<td width="114" valign="top"><strong>target</strong></td>
<td width="282" valign="top">
<p>The target that will be updated based on the source (the span in our case).</p>
<p>Again, notice the $get.</p>
</td>
</tr>
<tr>
<td width="114" valign="top"><strong>targetProperty</strong></td>
<td width="282" valign="top">
<p>The property name or path for the target.  In short, what you want to set (innerHTML in our case).</p>
</td>
</tr>
</tbody>
</table>
<p>You can find a full list of the <a href="http://msdn.microsoft.com/en-us/library/dd409292(VS.100).aspx" target="_blank">properties for Sys.Binding</a> on MSDN.</p>
<h2>Using Sys.Binding Declaratively</h2>
<p>You just saw the imperative creation of Sys.Binding, but if you’d rather declarative syntax, then this is the example for you.  I’m working off the same example so that you can easily see the similarities and differences between the snippets.</p>
<pre class="brush: xml;">&lt;body xmlns:sys="javascript:Sys"
      xmlns:binding="javascript:Sys.Binding"
      sys:activate="simpleForm"&gt;
    &lt;div id="simpleForm"&gt;
        Name:
         &lt;input id="name" type="text"
             sys:attach="binding"
            binding:source="{{ $get('name') }}"
            binding:path="value"
            binding:target="{{ $get('nameDisplay') }}"
            binding:targetProperty="innerHTML"/&gt;
        &lt;br /&gt;
        &lt;span id="nameDisplay"&gt;&lt;/span&gt;
    &lt;/div&gt;
&lt;/body&gt;</pre>
<p>Comparing this code to that of the imperative version, it should be pretty easy to pick out the similarities.  Instead of defining the properties for the Sys.Binding component in code, they are now added as attributes to the textbox.  Also, the sys:attach coupled with the xmlns:binding=”javascript:Sys.Binding” replaces the first parameter in the $create call from the imperative example.  Other than that, there shouldn’t be anything here that looks strange, if it does, refer back to my <a href="http://blogs.visoftinc.com/archive/2009/04/28/ASP.NET-4.0-AJAX-Preview-4-Client-Templates.aspx">client template post</a>.</p>
<h2>Live Binding Syntax</h2>
<p>Now that you’ve seen an example of live binding in action, let’s take a minute and look at the options available to us with live binding.</p>
<p>The first is the binding type <a href="http://msdn.microsoft.com/en-us/library/dd448879(VS.100).aspx#data_binding" target="_blank">defined in MSDN</a> as an “inline expression evaluation.”  This is commonly referred to as one-way/one-time when talking about binding, but the double curly braces syntax is also used to evaluate expressions (for example the attribute <span class="attr">binding:source=”{{ $get(‘name’) }}” from the last example).  When it used as a binding type, such as &lt;span&gt;{{ name }}&lt;/span&gt;, this simply means that expression is only handled when the template is bound/re-bound. </span></p>
<p>Next up is one-way and two-way binding.  The syntax for these bindings is {binding propertyName}, as you’ve seen before.  The syntax is the same since the determination of using one-way or two-way is based on the element itself.  One-way binding is the default mode of binding for HTML properties and context.  For input controls however, two-way binding is the default.  You can see this in action in the first example we looked at, binding within the DataView.  As a refresher, here is the pertinent snippet again:</p>
<pre class="brush: xml;">Name: &lt;input id="name" type="text" value="{binding name}" /&gt;&lt;br /&gt;
&lt;span id="nameDisplay"&gt;{binding name}&lt;/span&gt;</pre>
<p>If the default behavior isn’t desired, for example if you only wanted one-way binding on a textbox, you can specify the <a href="http://msdn.microsoft.com/en-us/library/dd409321(VS.100).aspx" target="_blank">mode</a> of the binding.  This can be done within the inline markup as so:</p>
<pre class="brush: xml;">Name: &lt;input id="name" type="text" value="{binding name, mode=oneWay}" /&gt;&lt;br /&gt;
&lt;span id="nameDisplay"&gt;{binding name}&lt;/span&gt;</pre>
<p>We’ll look a bit closer at binding modes in the next section, but one thing to take away from the syntax here is that you can specify properties for Sys.Binding within the HTML markup.  Another common property that you may set would be the source. For example, in a master-detail type setup where you have a master DataView and a detail DataView, you may have something along the lines of:</p>
<pre class="brush: xml;">&lt;div id="detailView" class="sys-template"
    sys:attach="dataview"
    dataview:data="{binding selectedData, source={{master}} }"&gt;</pre>
<p>You see that syntax a bit later in the Master/Detail example.  In addition to mode and source, another property that you’ll often see is the convert and convertBack properties.  These allow you to call functions when either updating the target (convert) or updating the source (convertBack).  For example:</p>
<pre class="brush: xml;">&lt;label&gt;Inches: &lt;/label&gt;
&lt;input id="inches" type="text"
     value="{binding num, convert=toInches, convertBack=toFeet }" /&gt;
&lt;br /&gt;
&lt;label&gt;Feet: &lt;/label&gt;
&lt;input id="feet" type="text" value="{binding num }" /&gt;</pre>
<p>In this snippet the Inches textbox will call toFeet when updating the Feet textbox.  When the Feet textbox is updated and the binding happens on the Inches textbox, it will first be converted to inches using the toInches method.</p>
<h2>Binding Modes</h2>
<div>In the last section we looked at the syntax for live binding, and I introduced the mode functionality.  The binding modes come from the “enumerator” Sys.BindingMode and contains five options (similar to those in WPF).  Let’s take a closer look at each one of them within the context of the HTML markup expressions.  Remember these are simply just properties for the Sys.Binding class, so these are the enumerations you can use if you set the mode property via JavaScript instead of doing it in the markup.</div>
<h3>Sys.BindingMode.auto</h3>
<p>This is the default binding mode that you’ve seen already.  Two-way binding on an input control, and one-way binding on a context-type elements such as spans.  If for some reason you want to manually set the mode to auto, you can do this as well, but it’s not required.</p>
<pre class="brush: xml;">&lt;div id="defaultBinding" class="sys-template"
    sys:attach="dataview"
     dataview:data="{{ { name:'' } }}"&gt;
    &lt;label&gt;Name: &lt;/label&gt;
    &lt;input id="name" type="text" value="{binding name, mode=auto}" /&gt;&lt;br /&gt;
    &lt;label&gt;Echo: &lt;/label&gt;
    &lt;span id="nameDisplay"&gt;{binding name, mode=auto}&lt;/span&gt;
&lt;/div&gt;</pre>
<h3>Sys.BindingMode.twoWay</h3>
<p>This is the default binding mode for input controls.  In this snippet, I’ve explicitly set both inputs to twoWay, although I could have left the mode specification off since it is the default.  In this snippet, when you update either textbox, the other one will be updated with the same value.</p>
<pre class="brush: xml;">&lt;div id="twoWayBinding" class="sys-template"
    sys:attach="dataview"
     dataview:data="{{ { name:'' } }}"&gt;
    &lt;label&gt;Name: &lt;/label&gt;
    &lt;input id="name1" type="text" value="{binding name, mode=twoWay}" /&gt;&lt;br /&gt;
    &lt;label&gt;Echo: &lt;/label&gt;&lt;input id="nameDisplay1" type="text" value="{binding name, mode=twoWay}" /&gt;
&lt;/div&gt;</pre>
<h3>Sys.BindingMode.oneWay</h3>
<p>Again, this is the default binding mode for properties and context-type HTML elements (e.g. span, div, etc).  You can specify this mode on an input control in order to override the default two-way binding.  In this snippet, when you update the Name textbox it will be displayed in the Echo textbox, but changing Echo won’t update Name since the Echo textbox is oneWay.</p>
<pre class="brush: xml;">&lt;div id="oneWayBinding" class="sys-template"
    sys:attach="dataview"
     dataview:data="{{ { name:'' } }}"&gt;
    &lt;label&gt;Name: &lt;/label&gt;
    &lt;input id="name2" type="text" value="{binding name}" /&gt;&lt;br /&gt;
    &lt;label&gt;Echo: &lt;/label&gt;
    &lt;input id="nameDisplay2" type="text" value="{binding name, mode=oneWay}" /&gt;
&lt;/div&gt;</pre>
<h3>Sys.BindingMode.oneWayToSource</h3>
<p>This binding works opposite to the last oneWay binding example.  In this case, changes to the Echo textbox will update the Name textbox, but updating Name won’t change Echo.</p>
<pre class="brush: xml;">&lt;div id="oneWayBinding" class="sys-template"
    sys:attach="dataview"
     dataview:data="{{ { name:'' } }}"&gt;
    &lt;label&gt;Name: &lt;/label&gt;
    &lt;input id="name2" type="text" value="{binding name}" /&gt;&lt;br /&gt;
    &lt;label&gt;Echo: &lt;/label&gt;
    &lt;input id="nameDisplay2" type="text" value="{binding name, mode=oneWay}" /&gt;
&lt;/div&gt;</pre>
<h3>Sys.BindingMode.oneTime</h3>
<p>In oneTime mode, the element will only be updated when the template is first instantiated.  For this snippet, the Name and Echo textboxes will be updated with my name and will be bound to both textboxes since it is defined in the object literal being passed to the DataView.  Changing the Name textbox in this case won’t update the Echo box.</p>
<pre class="brush: xml;">&lt;div id="oneTimeBinding" class="sys-template"
    sys:attach="dataview"
     dataview:data="{{ { name:'Damien' } }}"&gt;
    &lt;label&gt;Name: &lt;/label&gt;
    &lt;input id="name4" type="text" value="{binding name}" /&gt;&lt;br /&gt;
    &lt;label&gt;Echo: &lt;/label&gt;
    &lt;input id="nameDisplay4" type="text" value="{binding name, mode=oneTime}" /&gt;
&lt;/div&gt;</pre>
<h3>The “Classic” Example: Master/Detail</h3>
<p>Typically when looking up live binding, you’ll come across some kind of master/detail sample.  To keep with the “tradition” we’ll work through an example using SQL 2008, the Entity Framework, and ADO.NET Data Services server-side, and the ASP.NET AJAX DataView client-side.  Again, keeping with the trend of seeing how ASP.NET AJAX can be used outside of ASP.NET, the hosting page will simply be a standard HTML page.  In this sample we will be keeping a list of blogs that we enjoy.  We’ll add the blogs to the page one at a time, and we will persist the changes back to the database all at once thanks to ADO.NET Data Services.</p>
<h3>Server-Side Code</h3>
<p>First, we’ll start with a simple SQL 2008 Express Database that contains a single table named “blog.”  The schema is shown in Figure 1.</p>
<p><img style="margin: 0px 0px 5px; display: inline; border-width: 0px;" title="Figure 1 - The Blog Table" src="http://blogs.visoftinc.com/wp-content/uploads/Figure%201%20-%20The%20Blog%20Table.png" border="0" alt="Figure 1 - The Blog Table" width="281" height="152" /><br />
<strong>Figure 1 – The Database Schema</strong></p>
<p>Next up is the Entity Framework.  Simply add an ADO.NET Entity Data Model to the project.  I’ll name this BlogModel.edmx.  I’ll then use the “Generate from Database” option when prompted.  I’ve accepted the defaults for everything else.  We now have a single entity based on the blog table.  I’ve changed the EntitySet name to Blogs in order to make our service clearer when calling it, for example to get an item with an ID of 1, /BlogService.svc/<strong>Blogs</strong>(1) instead of /BlogService.svc/<strong>Blog</strong>(1) if I had left the default EntitySet name.</p>
<p><img style="margin: 0px; display: inline; border-width: 0px;" title="Figure 2 - The Blog Entity" src="http://blogs.visoftinc.com/wp-content/uploads/Figure%202%20-%20The%20Blog%20Entity.png" border="0" alt="Figure 2 - The Blog Entity" width="171" height="168" /></p>
<p><strong>Figure 2 – The Blog Entity</strong></p>
<p>Now that the database and the entity model are in place, the next step is to expose the entities via ADO.NET Data Services.  To do this, simply add an “ADO.NET Data Service.”   I’ve named my service “BlogService.svc.”  Then we need to configure the service, which involves specifying our entities to expose and configuring the rules for our service.  Since this is just a test service, I’ve opened all operations to all entities.  In addition I’ve configured the service to use verbose errors, and to include the exception details in an error.  <strong><em>In a production application, these settings should not be used, as we’re exposing everything to everyone.</em></strong></p>
<pre class="brush: csharp;">[ServiceBehavior(IncludeExceptionDetailInFaults=true)]
public class BlogService : DataService&lt;BlogsModel.BlogsEntities&gt;{
    public static void InitializeService(IDataServiceConfiguration config)
    {
        config.UseVerboseErrors = true;
        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
    }
}</pre>
<p>Now that the server side is configured, let’s test it out in the browser.  One thing you need to do before testing an ADO.NET Data Service is to make sure the “Feed View” is turned off in your browser.  For the XML representation of the data, ADO.NET Data Services uses ATOM, which RSS feeds use as well.  The browser, being helpful, will use the “Feed View” trying to “pretty” up the display of your service, when in fact we won’t see the raw XML data.  To turn off Feed View in Internet Explorer, simply go to Tools &gt;&gt; Internet Options &gt;&gt; Content Tab &gt;&gt; Feed Settings &gt;&gt; Uncheck “Turn on feed reading view.”  Now we can start browsing our service.</p>
<p>Calling the BlogService.svc directly, this will show us the collections available for us to use.  Simply browse to “/BlogService.svc” in the root of the application.  Next, let’s test the Blogs collection by browsing to “BlogService.svc/Blogs” and finally use “BlogService.svc/Blogs(1)” to access the entry with an ID of 1.</p>
<p><img style="margin: 0px; display: inline; border-width: 0px;" title="Figure 3 - Testing the Data Service" src="http://blogs.visoftinc.com/wp-content/uploads/Figure%203%20-%20Testing%20the%20Data%20Service.png" border="0" alt="Figure 3 - Testing the Data Service" width="657" height="425" /></p>
<p><strong>Figure 3 &#8211; Testing the ADO.NET Data Service</strong></p>
<h3>Client-Side Code</h3>
<p>Now that the server work is done, let’s move on to the client code.  The user interface will allow us to perform the standard CRUD (Create, Read, Update, Delete) operations using ADO.NET Data Services.  We will list the blogs that are found in the database and add a snapshot of the site using a cool service I discovered called <a href="http://www.bitpixels.com/" target="_blank">BitPixels.com</a>.  This site serves thumbnails of web pages without requiring a registration, which is perfect for a demo since you can download my sample code and run this on your machine without having to worry about registering to get it to work.</p>
<p>Here’s an example of it fully working:</p>
<p><a href="/wp-content/uploads/MasterDetail_1.gif"><img style="display: inline; border-width: 0px;" title="Master Detail Example" src="http://blogs.visoftinc.com/wp-content/uploads/MasterDetail_thumb.gif" border="0" alt="Master Detail Example" width="484" height="248" /></a></p>
<blockquote><p>An important thing to note on the example, changes aren’t persisted until they are saved back to the server.  We’ll see how this is accomplished when we look at the JavaScript code.</p></blockquote>
<p>The first difference with this example from the others that you have seen in my previous posts (<a href="http://blogs.visoftinc.com/archive/2009/05/21/ASP.NET-4.0-AJAX-Preview-4-JavaScript-Observer-Pattern.aspx">Sys.Observer</a> and <a href="http://blogs.visoftinc.com/archive/2009/04/28/ASP.NET-4.0-AJAX-Preview-4-Client-Templates.aspx">Client Templates</a>) is the JavaScript files being referenced.  We’re still using MicrosoftAjax.js and MicrosoftAjaxTemplates.js, but in addition we need to reference MicrosoftAjaxAdoNet.js.  This library allows us to work very easily with ADO.NET Data Services.  The script references should look like the following:</p>
<pre class="brush: xml;">&lt;script type="text/javascript" src="scripts/MicrosoftAjax.debug.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="scripts/MicrosoftAjaxTemplates.debug.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="scripts/MicrosoftAjaxAdoNet.debug.js"&gt;&lt;/script&gt;</pre>
<p>Now, onto the HTML markup.  There is a fair amount going on here, but some of it should look familiar to you.</p>
<pre class="brush: xml;">&lt;body   xmlns:sys="javascript:Sys"
        xmlns:dataview="javascript:Sys.UI.DataView"
        sys:activate="*"&gt;
    &lt;div class="tools"&gt;
        &lt;input type="button" value="Add" onclick="addBlog()" /&gt;
        &lt;input type="button" value="Save" onclick="BlogService.dataContext.saveChanges()" /&gt;
        &lt;input type="button" value="Reload"
            onclick="$find('blogList').fetchData(null, null, Sys.Data.MergeOption.overwriteChanges)" /&gt;
    &lt;/div&gt;
    &lt;div id="blogList" class="sys-template"
        sys:attach="dataview"
        dataview:dataprovider="{{ BlogService.dataContext }}"
        dataview:fetchoperation="Blogs"
        dataview:ondataloading="{{ dataLoading }}"
        dataview:autofetch="true"
        dataview:selecteditemclass="blogSelected"
        dataview:initialselectedindex="0"
        dataview:sys-key="master"
        dataview:oncommand="{{ dvCommand }}"&gt;
        &lt;div class="blogBlock" sys:command="Select"&gt;
            &lt;div class="blogTools"&gt;
                &lt;div class="blogDelete" sys:command="Delete"
                    sys:commandargument="{{$index}}"&gt;X&lt;/div&gt;
            &lt;/div&gt;
            &lt;img alt="{binding Name}" height="75" width="100"
                sys:src="{binding Url, convert=toSnapshot}" /&gt;
            &lt;hr /&gt;
            &lt;a href="{binding Url}"&gt;{binding Name}&lt;/a&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;hr style="clear:left;" /&gt;
    &lt;div id="detailView" class="sys-template detailsForm"
        sys:attach="dataview"
        dataview:data="{binding selectedData, source={{master}} }" &gt;
        &lt;label&gt;Name: &lt;/label&gt;&lt;input type="text" value="{binding Name}" /&gt;&lt;br /&gt;
        &lt;label&gt;Url: &lt;/label&gt;&lt;input type="text" value="{binding Url}" /&gt;
    &lt;/div&gt;
&lt;/body&gt;</pre>
<p>Let’s go through the code in chunks</p>
<ul>
<li><strong>Lines 1 – 3</strong>: This shouldn’t be anything new, you first saw this when working with the <a href="http://blogs.visoftinc.com/archive/2009/04/28/ASP.NET-4.0-AJAX-Preview-4-Client-Templates.aspx">DataView declaratively</a>.</li>
<li><strong>Lines 4 – 9:</strong> This section defines the buttons that allow us to Add, Save, and Reload.
<ul>
<li><strong>Line 5</strong>: For adding, I’m calling a custom JavaScript function which you’ll see in a moment, addBlog().</li>
<li><strong>Line 6</strong>: Using the ADO.NET Data Context, we can persist the changes back to the database.  Instead of simply defining a variable (e.g. dataContext), I created a simple JavaScript object (BlogService) to hold the properties that we need to work with (dataContext, which is a Sys.Data.AdoNetDataContext, and an observable array “data” that is made observable with Sys.Observer.makeObservable).  You’ll see this in the JavaScript code.</li>
<li><strong>Line 7 &amp; 8:</strong> This input button reloads the data.  This uses the method “fetchData” that is found on the DataView object.  The $find shortcut gets the DataView from the blogList DIV element, allowing us to call fetchData.  It takes four parameters, a success callback, failed callback, merge option, and a user context.  For the sake of reloading the DataView, the first two parameters (the callbacks) are null since the DataView handles those for us. The third is a type of <a href="http://msdn.microsoft.com/en-us/library/dd483403(VS.100).aspx" target="_blank">Sys.Data.MergeOption</a> and we want to reload everything from the server.  Finally, we don’t need to specify anything for the user context, so that parameter is excluded.</li>
</ul>
</li>
<li><strong>Lines 10 – 19:</strong> This is the setup of our “master” div.  This displays the website thumbnails, contains a delete button, and allows us to select an item.
<ul>
<li><strong>Line 10:</strong> Nothing new here, just an id and a class of “sys-template.”  Remember, this class needs to be on all of your DataViews and you should have a style defined as “display: none;” for this.  Doing this permits the AJAX library to show the content only after it has been bound.</li>
<li><strong>Line 11: </strong>You’ve seen this many times before, we’re simply attaching the DataView “behavior” to the div.</li>
<li><strong>Line 12: </strong>Now we begin setting the properties we need for the DataView.  Here we are telling the DataView to use a <a href="http://msdn.microsoft.com/en-us/library/dd393657(VS.100).aspx" target="_blank">dataProvider</a>.  The provider here is a Sys.Data.AdoNetDataContext and is defined in our JavaScript code. I’ve assigned it to a simple object, “BlogService” to keep the global variables in one place.</li>
<li><strong>Line 13:</strong> The fetchOperation is used to define the entity set (from ADO.NET Data Services) that we want to display.  There is only one in this example and that is “Blogs.”  Recall we accessed this earlier using the browser (e.g. “BlogService.svc/Blogs”).</li>
<li><strong>Line 14:</strong> This is an important event that is being wired up <a href="http://msdn.microsoft.com/en-us/library/dd483464(VS.100).aspx" target="_blank">dataLoading</a> via the <a href="http://msdn.microsoft.com/en-us/library/dd483408(VS.100).aspx" target="_blank">onDataLoading</a> method. This fires when, you guessed it, the data loads.  Here we’re calling a custom JavaScript function named “dataLoading” that I have defined in the page.  Within this function that you’ll see in the JavaScript code below, the data is put into an observable collection.  This collection is where our changes will take place and how the DataView and the live bindings actually do the automatic updates.  All thanks to the <a href="http://blogs.visoftinc.com/archive/2009/05/21/ASP.NET-4.0-AJAX-Preview-4-JavaScript-Observer-Pattern.aspx" target="_blank">Sys.Observer</a> object.</li>
<li><strong>Line 15:</strong> You saw this back in my <a href="http://blogs.visoftinc.com/archive/2009/04/28/ASP.NET-4.0-AJAX-Preview-4-Client-Templates.aspx">client templates post</a> when using the WCF service.  Setting <a href="http://msdn.microsoft.com/en-us/library/dd393610(VS.100).aspx" target="_blank">autoFetch</a> to true is used when we have a dataProvider.  This tells the DataView to retrieve the data when the page loads.</li>
<li><strong>Line 16 &amp; 17:</strong> The DataView has built-in functionality for handling item selection.  In line 16, we can define a CSS class for the item when it is selected (<a href="http://msdn.microsoft.com/en-us/library/dd393577(VS.100).aspx" target="_blank">selectedItemClass</a>).  In line 17, we are telling the DataView to initially select the first item in the list when the page loads (<a href="http://msdn.microsoft.com/en-us/library/dd409286(VS.100).aspx" target="_blank">initialSelectedIndex</a>).</li>
<li><strong>Line 18: </strong>The purpose of <strong>sys-key</strong> is to create a local variable that is a reference to the current component.  This allows us to refer to it (line 37), without needing to use $find.  (Thanks to <a href="http://weblogs.asp.net/bleroy/archive/2009/03/18/microsoft-ajax-4-0-preview-4-now-available.aspx#6995062" target="_blank">Bertrand Le Roy for pointing this out</a>)</li>
<li><strong>Line 19:</strong> This may look familiar from server-side code that you have written (e.g. DataGrid).  The <a href="http://msdn.microsoft.com/en-us/library/dd393672(VS.100).aspx" target="_blank">onCommand</a> method allows us to handle commands that are raised from the component.  The reason for handling this is the custom “delete” command on Line 22.</li>
</ul>
</li>
<li><strong>Lines 20 – 31:</strong> This is the master DataView’s content.
<ul>
<li><strong>Line 20:</strong> The first of two commands that we need to handle. Select is a command that the DataView handles automatically for us.  When you click inside the div, the DataView handles this event by setting the <a href="http://msdn.microsoft.com/en-us/library/dd409319(VS.100).aspx" target="_blank">selectedData</a> property (which will be used in the edit form on Line 37), setting the <a href="http://msdn.microsoft.com/en-us/library/dd393725(VS.100).aspx" target="_blank">selectedIndex</a> property, and also setting the <a href="http://msdn.microsoft.com/en-us/library/dd393577(VS.100).aspx" target="_blank">selectedItemClass</a>.</li>
<li><strong>Line 22 &amp; 23:</strong> The second command that we need to handle is delete.  To do this, we set the sys:command to “Delete” on Line 22.  This command will be bubbled up to our custom handler since we set the onCommand method of the DataView on Line 19.  In addition to custom events, we can have custom event args.  {{ $index }} evaluates to the index of the item as generated by the underlying collection.</li>
<li><strong>Line 27: </strong>This line is of interest since we are using the convert property of the binding.  Because of this, the src attribute needs to be prefixed with the sys namespace.  In some instances like this one, we need to prefix the attribute with sys in order to obtain the full functionality.  The convert function specified here is a custom one that will either set an empty image or change the src to the one that grabs the website snapshot.</li>
</ul>
</li>
<li><strong>Lines 35 – 40:</strong> This is the “detail” DataView, or in our case the edit form.
<ul>
<li><strong>Line 37:</strong> This is really the only item of interest in the edit form since everything else is pretty standard.  Here the binding is a bit special.  We are binding to the <a href="http://msdn.microsoft.com/en-us/library/dd409319(VS.100).aspx" target="_blank">selectedData</a> property of the “master” DataView.  The {{master}} refers to the sys-key defined in Line 18.</li>
</ul>
</li>
</ul>
<p>Now that you fully understand the HTML, let’s move onto the JavaScript.  For the JavaScript I have added all of the comments inline instead of a full discussion after the fact to make it easier.</p>
<pre class="brush: js;">// Create an empty object to store global variables
//   - dataContext: The AdoNetDataContext
//   - data: An observable "view" of the data
var BlogService = {};
 BlogService.dataContext = $create(
    Sys.Data.AdoNetDataContext,
    { serviceUri: "BlogService.svc" }
);
function dataLoading(sender, args) {
    // BlogService.data is where our changes will take place
    // You can think of this as a "ViewModel"
    // See http://forums.asp.net/p/1405579/3060650.aspx for more info
    BlogService.data = args.get_data();
    Sys.Observer.makeObservable(BlogService.data);
}
function addBlog() {
    // Create a new Blog entity
    var newBlog = { Name: 'Blog Name', Url: '' };
    // Add the blog to the DataContext
    BlogService.dataContext.insertEntity(newBlog, "Blogs");
    // Add the blog to our "ViewModel"
    BlogService.data.add(newBlog);
}
function toSnapshot(url) {
    // Either return a blank image
    if (url.substring(0, 7) !== 'http://')
        return 'nothumbnail.jpg';
    // Or use the bitpixels.com path to get a thumbnail
    return 'http://img.bitpixels.com/getthumbnail?url=' + url;
}
function dvCommand(sender, args) {
    // Test for our custom delete command
    if (args.get_commandName() === 'Delete') {
        // Get the index that we set on the delete button
        var index = args.get_commandArgument();
        // Get the entity from the local data
        var deletedBlog = BlogService.data[index];
        // Remove the entity from the ADO.NET Data Service
        BlogService.dataContext.removeEntity(deletedBlog);
        // Remove from the local collection
        BlogService.data.remove(deletedBlog);
        // Set the DataView's selected index
        if (index &gt;= BlogService.data.length) index--;
        $find('blogList').set_selectedIndex(index);
    }
}</pre>
<h2>Conclusion</h2>
<p>ASP.NET 4.0 is one exciting release.  The ASP.NET AJAX features shown here are incredibly cool.  The best thing about ASP.NET AJAX is that we can start using the scripts today in our ASP.NET 3.5 SP1 applications thanks to Preview 4.  No need to install anything on the server, just simply reference the scripts.  I’m excited to see documentation has been released for ASP.NET 4.0 Beta 1 and I would recommend checking out the <a href="http://msdn.microsoft.com/en-us/library/bb397536(VS.100).aspx" target="_blank">ASP.NET AJAX Client Reference</a> on MSDN.  I’ve also included many links to it throughout this post.  Another helpful reference is the ASP.NET 4.0 and VS 2010 whitepaper, where you can see all the features of ASP.NET 4.0 as well as the <a href="http://www.asp.net/learn/whitepapers/aspnet40/#_Toc223325467" target="_blank">ASP.NET AJAX functionality</a>.</p>
<p>For other blogs on ASP.NET AJAX 4.0, be sure to check out:</p>
<ul>
<li>Bertrand Le Roy’s blog &#8211; <a title="http://weblogs.asp.net/bleroy/" href="http://weblogs.asp.net/bleroy/">http://weblogs.asp.net/bleroy/</a></li>
<li>Jim Wang’s blog: <a title="http://weblogs.asp.net/jimwang/default.aspx" href="http://weblogs.asp.net/jimwang/default.aspx">http://weblogs.asp.net/jimwang/default.aspx</a></li>
<li>Politian’s blog: <a title="http://politian.wordpress.com/" href="http://politian.wordpress.com/">http://politian.wordpress.com/</a></li>
</ul>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:7e9d6233-b43c-420b-a343-641e4819c088" class="wlWriterSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/ASP.NET">ASP.NET</a>,<a rel="tag" href="http://technorati.com/tags/AJAX">AJAX</a></div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.visoftinc.com/2009/05/27/asp-net-4-0-ajax-preview-4-data-binding/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

