<?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>Jason Rowe &#187; .Net</title>
	<atom:link href="http://jasonrowe.com/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://jasonrowe.com</link>
	<description>Digging into the Details</description>
	<lastBuildDate>Fri, 23 Jul 2010 04:40:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Top 5 Features of Code First Entity Framework CTP4</title>
		<link>http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=top-5-features-of-code-first-entity-framework-ctp4</link>
		<comments>http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 16:19:26 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[EF]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/</guid>
		<description><![CDATA[&#160; The latest release of Entity Framework CTP4 has some nice but unexpected changes. They introduced DbContext and DbSet to simplify model caching, database provisioning, schema creation and connection management. Here are my top 5 favorite features of the release. &#8230; <a href="http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>The latest release of Entity Framework CTP4 has some nice but unexpected changes. They introduced DbContext and DbSet to simplify model caching, database provisioning, schema creation and connection management. Here are my top 5 favorite features of the release.</p>
<ol>
<li><strong><em>Less code and fewer Concepts.</em></strong> The coolest part is the use of convention over configuration. See the <a href="http://blogs.msdn.com/b/adonet/archive/2010/07/14/ctp4piwalkthrough.aspx">Productivity Improvements</a> walk through and <a href="http://blogs.msdn.com/b/efdesign/archive/2010/06/01/conventions-for-code-first.aspx">Conventions for code first</a>. I like the extra touch that DbContext&#160; will create the database for you if you want. No code to write. Just use the default CreateDatabaseOnlyIfNotExists. </li>
<li><em><strong>Simplified Database Experience.</strong></em> With the introduction of DbContext and DbSet. EF now takes care of database provisioning, schema creation and connection management. Nice! My favorite part is the Interface IDbConnectionFactory to allow creation of your own conventions. </li>
<li><strong>Backwards Compatible.</strong> Yes, this is a feature when it comes to CTP’s and Betas. Some projects might just throw stuff away or completely change things on you. EF allows you to still use ObjectContext or <a href="http://blogs.msdn.com/b/efdesign/archive/2010/03/30/data-annotations-in-the-entity-framework-and-code-first.aspx">Data Annotations</a> for advanced scenarios where common conventions don’t work for you. </li>
<li><strong>Simplified Configuration Experience.</strong> As I mentioned you can use annotations for this but you also have another cool option. DbContext includes a virtual method that can be overridden to do configuration right in the class. This means no need for separate configuration classes now. I definitely like having it all in one place. Much cleaner and easy to read. </li>
<li><strong>Testability </strong>IDbSet&lt;TEntity&gt; allows you to define an interface that can be implemented by your derived context. This allows the context to be replaced with an in-memory test double for testing. </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/07/18/top-5-features-of-code-first-entity-framework-ctp4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EF CTP3 Code First and Castle Windsor</title>
		<link>http://jasonrowe.com/2010/07/12/ef-ctp3-code-first-and-castle-windsor/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=ef-ctp3-code-first-and-castle-windsor</link>
		<comments>http://jasonrowe.com/2010/07/12/ef-ctp3-code-first-and-castle-windsor/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 04:31:28 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[Code First]]></category>
		<category><![CDATA[EF]]></category>
		<category><![CDATA[Windsor]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1280</guid>
		<description><![CDATA[Awhile back I wrote a simple Holiday service to try out Entity Framework &#34;Code First&#34; (the new name for Code Only). I&#8217;ve upgraded the bits and tried out some of the new features of CTP3 using this walkthrough as a &#8230; <a href="http://jasonrowe.com/2010/07/12/ef-ctp3-code-first-and-castle-windsor/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Awhile back I wrote a simple Holiday service to try out Entity Framework &quot;Code First&quot; (the new name for Code Only). I&#8217;ve upgraded the bits and tried out some of the new features of CTP3 <a href="http://blogs.msdn.com/b/adonet/archive/2009/06/22/feature-ctp-walkthrough-code-only-for-the-entity-framework.aspx">using this walkthrough as a guide</a>. You can download my sample app from <a href="http://github.com/JasonRowe/EF-CTP3-HolidayService/zipball/master">git hub</a>.</p>
<p>In addition, I added Inversion of Control (IOC) using Castle Windsor and implemented a repository pattern. </p>
<p>My database generation script and test data now look like this.</p>
<pre class="brush: c#; ">

databasefactory.Create();
var repository = new HolidayRepository(databasefactory);

//... build up test data for xmas and newyear

repository.Add(xmas);
repository.Add(newYear);

//commit changes
var unitOfWork = new UnitOfWork(databasefactory);
unitOfWork.Commit();
</pre>
<p>The other interesting part of this sample project is using WCF and EF together and WCF dependency injection using Castle Windsor.</p>
<p>First I setup my interfaces and configuration files for EF and WCF.</p>
<pre class="brush: c#; ">

[DataContract]
public class Holiday : IEntity
{
    public long Id { get; set; }

    [DataMember]
    public string HolidayName { get; set; }

    [DataMember]
    public DateTime HolidayDate { get; set; }

    [DataMember]
    public ICollection&lt;holidayevent&gt; HolidayEvents {get; set;}
}
</pre>
<pre class="brush: c#; ">

[DataContract]
public class HolidayEvent : IEntity
{
    public long Id { get; set; }

    [DataMember]
    public string EventName { get; set; }

    [DataMember]
    public Holiday Holiday { get; set; }

    [DataMember]
    public long HolidayId { get; set; }
}
</pre>
<pre class="brush: c#; ">

public HolidayConfiguration()
{
    Property(h =&gt; h.Id).IsIdentity();
    Property(h =&gt; h.HolidayName).HasMaxLength(1000).IsRequired();

    Relationship(e =&gt; e.HolidayEvents).FromProperty(h =&gt; h.Holiday);
}
</pre>
<pre class="brush: c#; ">

public HolidayEventConfiguration()
{
    Property(e =&gt; e.Id).IsIdentity();
    Property(e =&gt; e.EventName).HasMaxLength(1000).IsRequired();

    //HolidayId is a FK property and Holiday is a navigation property backed by this FK
    Relationship(e =&gt; e.Holiday).FromProperty(h =&gt; h.HolidayEvents).HasConstraint((e, h) =&gt; e.HolidayId == h.Id);
}
</pre>
<p>In my .svc file I use a custom factory to do dependency injection</p>
<pre class="brush: c#; ">

Factory=&quot;Castle.Facilities.WcfIntegration.WindsorServiceHostFactory, Castle.Facilities.WcfIntegration&quot;
</pre>
<p>On startup, I add my HolidayService as a component and add the DatabaseFactory as a parameter. The DatabaseFactory is used to setup my EF Object Context.</p>
<pre class="brush: c#; ">

container.Register(Component.For&lt;iholidayservice&gt;().ImplementedBy&lt;holidayservices&gt;().DependsOn
    (Property.ForKey(&quot;databaseFactory&quot;).Eq(databaseFactory)));
</pre>
<p>A great resource for seeing many of the new features in EF CTP3 is the <a href="http://shrinkr.codeplex.com/">shrinker project</a>. This is where I found many great examples of property facets and relationships using Entity Framework.</p>
<p></holidayservices></iholidayservice></holidayevent></p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/07/12/ef-ctp3-code-first-and-castle-windsor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Poor Mans Reverse Search with Lucene.net</title>
		<link>http://jasonrowe.com/2010/07/02/poor-mans-reverse-search-with-lucene-net/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=poor-mans-reverse-search-with-lucene-net</link>
		<comments>http://jasonrowe.com/2010/07/02/poor-mans-reverse-search-with-lucene-net/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 04:54:21 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Lucene]]></category>
		<category><![CDATA[lucene]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1268</guid>
		<description><![CDATA[As I mentioned in my last post I&#8217;ve been reading and learning about Lucene via Lucene in Action 2nd edition. Chapter 9.4, Fast memory-based indices, talks about MemoryIndex and InstantiatedIndex. MemoryIndex, contributed by Wolfgang Hoschek, is a fast RAM-only index &#8230; <a href="http://jasonrowe.com/2010/07/02/poor-mans-reverse-search-with-lucene-net/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my last <a href="http://jasonrowe.com/2010/06/23/lucene-in-action-net-samples/">post</a> I&#8217;ve been reading and learning about Lucene via Lucene in Action 2nd edition. Chapter 9.4, Fast memory-based indices, talks about MemoryIndex and InstantiatedIndex. </p>
<p>MemoryIndex, contributed by Wolfgang Hoschek, is a fast RAM-only index designed to test whether a single document matches a query. InstantiatedIndex, contributed by Karl Wettin, is similar, except it’s able to index and search multiple documents. Unfortunately, neither of these are yet ported to .Net. I thought about trying to port these but figured I would see if I could build a simple reverse search using the slower built in RamDirectory in Lucene and Lucene.net. </p>
<p>So what I want to create is a reverse search or on-the-fly matchmaking for documents. A simpler way to say that is I take a list of queries and check if they match a data object each time a data object is created. For simplicity sake I&#8217;m only working with the already ported Lucene code. </p>
<p>One cool features in Lucene version 2.9 was the addition of Near Real Time (NRT) searching. This seemed like a good fit for my scenario of trying to create a faster reverse search. It provides a way to search for documents that have not been committed yet. This helps take some of the overhead off when I need to add the one document to the index before running all the queries to test for matches. The explanation from the book says NRT enables you to rapidly search changes made to the index with an open IndexWriter, without having to first close or commit changes to that writer. </p>
<p>The NRT features allows me to do something like this: </p>
<p><em>It seems to be a big memory hog though so I made it disposable.</em></p>
<pre class="brush: c#; ">

 public class QueryProcessor : IDisposable
    {
        private readonly RAMDirectory _directory;
        private readonly IndexWriter _writer;

        public MetaQueryProcessor()
        {
            _directory = new RAMDirectory();
            _writer = new IndexWriter(_directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT), IndexWriter.MaxFieldLength.UNLIMITED);
            _writer.SetMergeFactor(2);
        }

        public void Optimize()
        {
            _writer.Optimize();
        }

        public List&lt;string&gt; Search(List&lt;metaqueryrequest&gt; requests, Document doc)
        {
            _writer.AddDocument(doc);

            var results = new List&lt;string&gt;();

            foreach (var request in requests)
            {
                var reader = _writer.GetReader();//Near-real-time search not commited

                var indexSearcher = new IndexSearcher(reader);

                var primitiveQuery = request.LuceneQuery.Rewrite(reader);

                var hits = indexSearcher.Search(primitiveQuery, 1);

                if (hits.totalHits &gt; 0)
                {
                    results.Add(request.QueryName);
                }
            }

            _writer.DeleteAll();

            return results;
        }

        #region IDisposable Members

        public void Dispose()
        {
            _directory.Close();
        }

        #endregion
    }
</pre>
<p><a href="http://jasonrowe.com/wp-content/uploads/2010/07/reverse_search.png"><img src="http://jasonrowe.com/wp-content/uploads/2010/07/reverse_search.png" alt="" title="reverse_search" class="alignnone size-full wp-image-1274" /></a></p>
<p>If you know of a faster way to accomplish this please let me know. For more background information on this topic see these resources. </p>
<ul>
<li><a href="http://lucene.apache.org/java/2_2_0/api/org/apache/lucene/index/memory/MemoryIndex.html">MemoryIndex contrib project Lucene</a> </li>
<li><a href=" http://lucene.apache.org/java/2_4_0/api/contrib-instantiated/org/apache/lucene/store/instantiated/InstantiatedIndex.html">InstantiatedIndex contrib project Lucene</a> </li>
</ul>
<p></string></metaqueryrequest></string></p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/07/02/poor-mans-reverse-search-with-lucene-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lucene in Action .Net Samples</title>
		<link>http://jasonrowe.com/2010/06/23/lucene-in-action-net-samples/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=lucene-in-action-net-samples</link>
		<comments>http://jasonrowe.com/2010/06/23/lucene-in-action-net-samples/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 03:22:39 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Lucene.Net]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1185</guid>
		<description><![CDATA[&#160; I started reading Lucene in Action by Otis Gospodnetic´ and Erik Hatcher.&#160; Lucene is a high performance, scalable Information Retrieval (IR) library. The library is in Java but I’m using the book to understand the Lucene .Net port. Why &#8230; <a href="http://jasonrowe.com/2010/06/23/lucene-in-action-net-samples/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>I started reading <a href="http://www.manning.com/hatcher3/">Lucene in Action</a> by Otis Gospodnetic´ and Erik Hatcher.&#160; Lucene is a high performance, scalable Information Retrieval (IR) library. The library is in Java but I’m using the book to understand the <a href="http://lucene.apache.org/lucene.net/">Lucene .Net</a> port.</p>
<p>Why buy a Java book to learn a .net Library? I couldn’t find a book specifically for the .Net version. Also, I wanted a 1000 foot level view of search technologies and because this is my first time working with IR. I was pleased to find the .net version is akin to the Java version presented in the book.</p>
<p>In some ways, learning from a different language has been beneficial. I invested more time converting the presented samples to C#.  I’ve also read <a href="http://www.amazon.com/Mathematics-Physics-Programmers-Game-Development/dp/1584503300">Mathematics and Physics for Programmers</a> which was completely written in a pseudo language. Again, lots of fun to convert the presented samples to a language I was more comfortable with.</p>
<p>It was also nice to find that the open source project <a href="http://code.google.com/p/subtext/source/browse/trunk/src/Subtext.Framework/Services/SearchEngine/SearchEngineService.cs">Subtext</a> is using Lucene .Net. They’ve worked out some locking issue recently and seem to be getting things setup in a nice way. Also, my co workers Kevin and Tim put together a nice library for Lucene .Net called <a href="http://code.google.com/p/activelucenenet/">ActiveLucene.Net &#8211; Attributed Lucene.Net</a>. The largest project seems to be <a href="http://linqtolucene.codeplex.com/">Linq to Lucene</a> but I haven&#8217;t looked at it yet. It was helpful to see how others are integrating Lucene into the Microsoft Web Platform.</p>
<p>
Anyway, here are the indexer and searcher in my C# interpretation. These are the first snippets presented in the book. These are a great way to get a jump start into understanding the basics.
</p>
<p><strong>Indexer</strong></p>
<pre class="brush: c#; ">

readonly static SimpleFSLockFactory _LockFactory = new SimpleFSLockFactory();

static void Main(string[] args)
{

    var dataPath = ConfigurationManager.AppSettings[&quot;DataDirectory&quot;];

    var indexPath = ConfigurationManager.AppSettings[&quot;IndexDirectory&quot;];

    if (!System.IO.Directory.Exists(dataPath))
    {
        throw new IOException(dataPath + &quot; directory does not exist&quot;);
    }

    DirectoryInfo indexInfo = new DirectoryInfo(indexPath);

    DirectoryInfo dataInfo = new DirectoryInfo(dataPath);

    Lucene.Net.Store.Directory indexDir = Lucene.Net.Store.FSDirectory.Open(indexInfo, _LockFactory);

    var start = DateTime.Now.TimeOfDay;
    var numIndexed = Index(indexDir, dataInfo);
    var end = DateTime.Now.TimeOfDay;

    var delta = end.TotalMilliseconds - start.TotalMilliseconds;

    Console.WriteLine(&quot;Indexing &quot; + numIndexed + &quot; files took &quot; + delta.ToString() + &quot; milliseconds&quot;);
}

public static int Index(Lucene.Net.Store.Directory indexDir, DirectoryInfo dataInfo)
{
    var writer = new IndexWriter(indexDir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), IndexWriter.MaxFieldLength.UNLIMITED);
    writer.SetMergePolicy(new LogDocMergePolicy(writer));
    writer.SetMergeFactor(5);

    try
    {
        var paths = dataInfo.EnumerateFiles(&quot;*.txt&quot;);

        foreach (var path in paths)
        {
            IndexFile(writer, path);
        }
    }
    catch (Exception ex)
    {
        writer.Close();
        throw ex;
    }

    var numIndexed = writer.MaxDoc();
    writer.Optimize();
    writer.Close();

    return numIndexed;
}

private static void IndexFile(IndexWriter writer, FileInfo file)
{
    if (!file.Exists)
    {
        return;
    }

    Console.WriteLine(&quot;Indexing &quot; + file.Name);

    Document doc = new Document();

    var path = file.FullName;

    System.IO.TextReader readFile = new StreamReader(path);

    doc.Add(new Field(&quot;contents&quot;, readFile));

    doc.Add(new Field(&quot;filename&quot;, file.Name,
        Field.Store.YES,
        Field.Index.ANALYZED,
        Field.TermVector.YES));

    writer.AddDocument(doc);
}
</pre>
<p><strong>Searcher</strong></p>
<pre class="brush: c#; ">

public static SimpleFSLockFactory _LockFactory = new SimpleFSLockFactory();

static void Main(string[] args)
{
    if (args.Length &lt; 2)
    {
        Console.WriteLine(&quot;Searcher takes two parameters&quot;);
        Console.WriteLine(&quot;Usage: ConsoleSearcher &lt;index dir&gt; &lt;query&gt;&quot;);
    }

    var indexInfo = new DirectoryInfo(args[0]);
    var query = args[1];

    if (!System.IO.Directory.Exists(args[0]))
    {
        throw new IOException(args[0] + &quot; directory does not exist&quot;);
    }

    SearchOption(indexInfo, query);
}

private static void SearchOption(DirectoryInfo indexInfo, string query)
{
    Lucene.Net.Store.Directory indexDir = Lucene.Net.Store.FSDirectory.Open(indexInfo, _LockFactory);

    IndexSearcher indexSearcher = new IndexSearcher(indexDir, true);

    QueryParser parser = BuildQueryParser();
    var luceneQuery = parser.Parse(query);

    var start = DateTime.Now.TimeOfDay;

    var hits = indexSearcher.Search(luceneQuery);
    var end = DateTime.Now.TimeOfDay;

    var delta = end.TotalMilliseconds - start.TotalMilliseconds;

    Console.WriteLine(&quot;Found &quot; + hits.Length() + &quot; document (s) (in &quot; + delta.ToString() + &quot; milliseconds) that matched query &#039;&quot; + query + &quot;&#039;:&quot;);

    for (int i = 0; i &lt; hits.Length(); i++)
    {
        Document doc = hits.Doc(i);

        Console.WriteLine(doc.Get(&quot;filename&quot;));
    }
}

private static QueryParser BuildQueryParser()
{
    var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, &quot;contents&quot;, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29));
    parser.SetDefaultOperator(QueryParser.Operator.AND);
    return parser;
}
</pre>
<p></query></query></p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/06/23/lucene-in-action-net-samples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Odata Osht! and some examples</title>
		<link>http://jasonrowe.com/2010/06/19/odata-osht-and-some-examples/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=odata-osht-and-some-examples</link>
		<comments>http://jasonrowe.com/2010/06/19/odata-osht-and-some-examples/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 08:14:31 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[odata]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/2010/06/19/odata-osht-and-some-examples/</guid>
		<description><![CDATA[  My head is spinning from looking at Odata tonight. I keep going back and forth on if this is the coolest thing in the world or just a way to browse data via the URI. Either way it&#8217;s fun. &#8230; <a href="http://jasonrowe.com/2010/06/19/odata-osht-and-some-examples/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
 </p>
<p>My head is spinning from looking at <a href="http://www.odata.org/">Odata</a> tonight.  I keep going back and forth on if this is the coolest thing in the world or just a way to browse data via the URI. Either way it&#8217;s fun.  Below are my notes and examples showing some limitations and features of Odata.
</p>
<p> The first area I had some misunderstandings was when working with collections. Take a look at this question on StackOverflow &#8220;<a href="http://stackoverflow.com/questions/2679471/use-linq-to-query-nested-odata-collection">use linq to query nested odata collection</a>&#8220;.  This pretty much sums up the issue I was stuck on for awhile.  How do relationships work and how can I query collections. This <a href="http://www.chriswoodruff.com/index.php/2010/03/22/odata-does-not-support-select-many-queries/">blog post</a> helped me start to understand how keys and collections work.
</p>
<p>Then, I find this <a href="http://blogs.msdn.com/b/pablo/archive/2010/01/26/implementing-only-certain-aspects-of-odata.aspx">post</a> and <a href="http://odataprimer.com/">this collection of resources</a>. Now, I&#8217;m back to being sold on oData. The ease of filtering data is amazing. <a href="http://msdn.microsoft.com/en-us/library/cc668793.aspx">Filters also support functions</a> if needed. Thanks to this <a href="https://blogs.msdn.com/b/alexj/archive/2009/11/18/tip-44-how-to-navigate-an-odata-compliant-service.aspx">tip</a> for pointing that out.
</p>
</p>
<p>
 </p>
<p>Here is a set of <a href="http://developer.netflix.com/docs/OData_Catalog">examples</a> for the Odata Netflix feed.  I&#8217;ve listed the URI with the corresponding C# expression below.
</p>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/Titles?$filter=Name%20eq%20%27The%20Name%20of%20The%20Rose%27'">http://odata.netflix.com/Catalog/Titles?$filter=Name eq &#8216;The Name of The Rose&#8217;</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from t in Titles
where t.Name == &quot;The Name of The Rose&quot;
select t)
</pre>
<p><a href="http://odata.netflix.com/Catalog/Titles?$filter=AverageRating%20lt%202%20and%20Instant/Available%20eq%20true">http://odata.netflix.com/Catalog/Titles?$filter=AverageRating lt 2 and Instant/Available eq true</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from t in Titles
where t.AverageRating &lt; 2 &amp;&amp; t.Instant.Available == true
select t)
</pre>
</p>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/Titles?$filter=ReleaseYear%20le%201989%20and%20ReleaseYear%20ge%201980%20and%20AverageRating%20gt%204&amp;$expand=Awards">http://odata.netflix.com/Catalog/Titles?$filter=ReleaseYear le 1989 and ReleaseYear ge 1980 and AverageRating gt 4&amp;$expand=Awards</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from t in Titles.Expand(&quot;Awards&quot;)
where t.ReleaseYear &lt; 1989 &amp;&amp; t.ReleaseYear &gt; 1980 &amp;&amp; t.AverageRating &gt; 4
select t)
</pre>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/Titles?$filter=Instant/Available%20eq%20true%20and%20%28Rating%20eq%20%27G%27%20or%20Rating%20eq%20%27PG-13%27%29">http://odata.netflix.com/Catalog/Titles?$filter=Type eq &#8216;Movie&#8217; and Instant/Available eq true and (Rating eq &#8216;G&#8217; or Rating eq &#8216;PG-13&#8242;)</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from t in Titles
where t.Type == &quot;Movie&quot; &amp;&amp; t.Instant.Available == true &amp;&amp; (t.Rating == &quot;G&quot; || t.Rating == &quot;PG-13&quot;)
select t)
</pre>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/Titles?$filter=Instant/Available%20eq%20true%20and%20%28Rating%20ne%20%27R%27%20and%20Rating%20ne%20%27NC-17%27%20and%20Rating%20ne%20%27UR%27%20and%20Rating%20ne%20%27NR%27%29">http://odata.netflix.com/Catalog/Titles?$filter=Type eq &#8216;Movie&#8217; and Instant/Available eq true and (Rating ne &#8216;R&#8217; and Rating ne &#8216;NC-17&#8242; and Rating ne &#8216;UR&#8217; and Rating ne &#8216;NR&#8217;)</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from t in Titles
where t.Type == &quot;Movie&quot; &amp;&amp; t.Instant.Available == true &amp;&amp; (t.Rating != &quot;R&quot; &amp;&amp; t.Rating != &quot;NC-17&quot; &amp;&amp; t.Rating != &quot;UR&quot; &amp;&amp; t.Rating != &quot;NR&quot;)
select t)
</pre>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/People?$filter=Name%20eq%20%27James%20Cameron%27&#038;$expand=Awards,TitlesDirected">http://odata.netflix.com/Catalog/People?$filter=Name eq &#8216;James Cameron&#8217;&#038;$expand=Awards,TitlesDirected</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from p in People.Expand(&quot;Awards&quot;).Expand(&quot;TitlesDirected&quot;)
where p.Name == &quot;James Cameron&quot;
select p)
</pre>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/Languages%28%27Japanese%27%29/Titles?$filter=Type%20eq%20%27Movie%27">http://odata.netflix.com/Catalog/Languages(&#8216;Japanese&#8217;)/Titles?$filter=Type eq &#8216;Movie&#8217;&#8221;</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from l in Languages
from t in l.Titles
where l.Name == &quot;Japanese&quot; &amp;&amp; t.Type == &quot;Movie&quot;
select t)
</pre>
<p>
 </p>
<p><a href="http://odata.netflix.com/Catalog/Languages%28%27French%27%29/Titles?$filter=Type%20eq%20%27Movie%27%20and%20Rating%20eq%20%27UR%27">http://odata.netflix.com/Catalog/Languages(&#8216;French&#8217;)/Titles?$filter=Type eq &#8216;Movie&#8217; and Rating eq &#8216;UR&#8217;</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from l in Languages
from t in l.Titles
where l.Name == &quot;French&quot; &amp;&amp; t.Type == &quot;Movie&quot; &amp;&amp; t.Rating == &quot;UR&quot;
select t)
</pre>
<p>
 </p>
<p><a href="http://netflix.cloudapp.net/Catalog/Genres%28%27Horror%27%29/Titles/$count?$filter=Type%20eq%20%27Movie%27">http://odata.netflix.com/Catalog/Genres(&#8216;Horror&#8217;)/Titles/$count?$filter=Type eq &#8216;Movie&#8217;</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from g in Genres
from t in g.Titles
where g.Name == &quot;Horror&quot; &amp;&amp; t.Type == &quot;Movie&quot;
select t).Count();
</pre>
<p><a href="http://odata.netflix.com/Catalog/Genres%28%27Horror%27%29/Titles?$filter=ReleaseYear%20le%201979%20and%20ReleaseYear%20ge%201970">http://odata.netflix.com/Catalog/Genres(&#8216;Horror&#8217;)/Titles?$filter=ReleaseYear le 1979 and ReleaseYear ge 1970</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from g in Genres
from t in g.Titles
where g.Name == &quot;Horror&quot; &amp;&amp; t.ReleaseYear &lt; 1979 &amp;&amp; t.ReleaseYear &gt; 1970
select t)
</pre>
<p>
<a href="http://odata.netflix.com/Catalog/Titles('BVIuO')">http://odata.netflix.com/Catalog/Titles(&#8216;BVIuO&#8217;))</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from t in Titles
where t.Id == &quot;BVIuO&quot;
select t)
</pre>
<p><a href="http://odata.netflix.com/Catalog/Genres%28%27Romantic%20Comedies%27%29/Titles?$filter=Type%20eq%20%27Movie%27%20and%20round%28AverageRating%29%20ge%205&#038;$orderby=year%28Instant/AvailableFrom%29">http://odata.netflix.com/Catalog/Genres(&#8216;Romantic Comedies&#8217;)/Titles?$filter=Type%20eq%20&#8242;Movie&#8217; and round(AverageRating) ge 5&amp;$orderby=year(Instant/AvailableFrom)</a>
	</p>
<p>
 </p>
<pre class="brush: c#; ">

(from g in Genres
from t in g.Titles
where g.Name == &quot;Romantic Comedies&quot; &amp;&amp; t.Type == &quot;Movie&quot; &amp;&amp; Math.Round(t.AverageRating.Value) &gt; 5
orderby t.Instant.AvailableFrom
select t)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/06/19/odata-osht-and-some-examples/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft WebCamp Chicago – I won a purse!</title>
		<link>http://jasonrowe.com/2010/06/13/microsoft-webcamp-chicago-%e2%80%93-i-won-a-purse/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=microsoft-webcamp-chicago-%25e2%2580%2593-i-won-a-purse</link>
		<comments>http://jasonrowe.com/2010/06/13/microsoft-webcamp-chicago-%e2%80%93-i-won-a-purse/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 02:32:56 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1048</guid>
		<description><![CDATA[  This weekend I drove to Chicago for Microsoft Web Camps not knowing what to expect. I definitely didn&#8217;t think I would win a purse and a cool t-shirt. So how did this happen?   Web Camps is a two &#8230; <a href="http://jasonrowe.com/2010/06/13/microsoft-webcamp-chicago-%e2%80%93-i-won-a-purse/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
 </p>
<p><span style="font-family:Arial; font-size:12pt">This weekend I drove to Chicago for <a href="http://www.webcamps.ms/">Microsoft Web Camps</a> not knowing what to expect.  I definitely didn&#8217;t think I would win a purse and a cool t-shirt.  So how did this happen?<br />
</span></p>
<p>
<img alt="" src="http://jasonrowe.com/uploaded_images/061410_0232_MicrosoftWe1.jpg"  width="213" height="430" />
	</p>
<p>
 </p>
<p><span style="font-family:Arial; font-size:12pt">Web Camps is a two day event. The first day is all learning and was presented by James Senior and Jon Galloway who did an excellent job.<br />
</span></p>
<p><span style="font-family:Arial; font-size:12pt"><br />
<img alt="" src="http://jasonrowe.com/uploaded_images/061410_0232_MicrosoftWe2.jpg" class="alignnone" width="356" height="268" /><br />
		</span></p>
<p><span style="font-family:Arial; font-size:12pt">The second day was a build day.  You get into groups and build an application.  Then at the end of the day all the teams got to demo.  Thanks to my team members Mark Greenway and Tim McManemy, we got first place!<br />
</span></p>
<p><span style="font-family:Arial; font-size:12pt">Our application was called Fact or Crap. Basically you could submit a statement and others could vote if it is true or false. We used MVC2, <a href="http://github.com/jquery/jquery-tmpl">JQuery templating</a>, and Entity Framework.<br />
</span></p>
<p><span style="font-family:Arial; font-size:12pt"><br />
		</span></p>
<p>
<img alt="" src="http://jasonrowe.com/uploaded_images/061410_0232_MicrosoftWe3.png" class="alignnone" width="499" height="85" /><br />
 </p>
<p><span style="font-family:Arial; font-size:12pt">Hopefully Microsoft will do this again next year. This was probably the most fun I have had programming in awhile. Everyone learned a ton and made some new friends.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/06/13/microsoft-webcamp-chicago-%e2%80%93-i-won-a-purse/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Silverlight Binding</title>
		<link>http://jasonrowe.com/2010/05/14/silverlight-binding-3/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=silverlight-binding-3</link>
		<comments>http://jasonrowe.com/2010/05/14/silverlight-binding-3/#comments</comments>
		<pubDate>Sat, 15 May 2010 01:42:13 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1040</guid>
		<description><![CDATA[  Binding is a fundamental part of Silverlight and allows developers to create a relationship between a UI property and a CLR object. Unfortunately, it can be a little confusing at first. Is it worth the trouble getting use to &#8230; <a href="http://jasonrowe.com/2010/05/14/silverlight-binding-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
 </p>
<p><span style="font-size:12pt">Binding is a fundamental part of Silverlight and allows developers to create a relationship between a UI property and a CLR object.  Unfortunately, it can be a little confusing at first. Is it worth the trouble getting use to the syntax?<br />
</span></p>
<p>
 </p>
<p style="text-align: center"><span style="font-size:28pt">&lt;object property=&#8221;{Binding}&#8221; &#8230;/&gt;<br />
</span></p>
<p>
 </p>
<p><span style="font-size:12pt">It&#8217;s entirely possible to update the Silverlight presentation layer without using binding.  Although with the use of binding you can make your code more reusable and easier to extend.  Especially if you have multiple web requests that update the view.  I&#8217;m not saying binding is a silver bullet.  It can be very frustrating to track down issues and getting the syntax correct. But used in the right situations it can be very useful.<br />
</span></p>
<p>
 </p>
<p><span style="font-size:12pt">I&#8217;m not a Silverlight expert and I won&#8217;t be able to cover every detail of binding.  I&#8217;ll start by covering some basic syntax. Then give an example using notification properties and dependencies properties.  Then I will finish with a list of links and resources to find more information about MVVM and Silverlight 4.<br />
</span></p>
<p>
 </p>
<p>
 </p>
<p><span style="font-size:16pt; text-decoration:underline"><strong>Basic Binding Syntax<br />
</strong></span></p>
<p>
 </p>
<h2><span style="font-size:12pt">Let&#8217;s look at an example using an object named Cat and we will bind to the Speak property.<br />
</span></h2>
<pre class="brush: c#; ">

namespace BindingPatterns.ViewModel
{
    public class Cat
    {
        public string Speak { get; set; }
    }
}
</pre>
</p>
<p>
 </p>
<p>From now on I won&#8217;t include this much XAML detail but I wanted to be clear on the first example.  Notice the name space of where the Cat class is located is added.</p>
<pre class="brush: xml; ">

&lt;usercontrol x:Class=&quot;BindingPatterns.MainPage&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    xmlns:data=&quot;clr-namespace:BindingPatterns.ViewModel&quot;
    mc:Ignorable=&quot;d&quot;
    d:DesignHeight=&quot;300&quot; d:DesignWidth=&quot;400&quot;&gt;

    &lt;/usercontrol&gt;&lt;usercontrol .Resources&gt;
        &lt;data :Cat x:Key=&quot;ViewModel&quot; Speak=&quot;meow&quot; /&gt;
    &lt;/usercontrol&gt;

    &lt;grid x:Name=&quot;LayoutRoot&quot;&gt;
        &lt;textblock x:Name=&quot;CatSound&quot; Text=&quot;{Binding Path=Speak, Source={StaticResource ViewModel}}&quot;&gt;&lt;/textblock&gt;
    &lt;/grid&gt;
</pre>
<p> </p>
<p><span style="font-size:12pt">I know this isn&#8217;t very useful but it&#8217;s only to demonstrate the binding.  What happens first in this example is the Cat class is instantiate as a static Resource. Then we set the Speak property to &#8220;meow&#8221;.  Finally we bind the TextBlock to the Speak property of that class.  We have to include the Source attribute to tell where the CLR binding is located.<br />
</span></p>
<p>
 </p>
<p><span style="font-size:12pt">Another way we could do this is using the data context.  Once &#8220;ViewModel&#8221; (which is the Cat class) is added to the DataContext we can reference directly in the TextBlock via the public property &#8220;Speak&#8221;.</span></p>
<pre class="brush: xml; ">

&lt;grid x:Name=&quot;LayoutRoot&quot; DataContext=&quot;{Binding Source={StaticResource ViewModel}}&quot;&gt;
    &lt;textblock x:Name=&quot;CatSound&quot; Text=&quot;{Binding Path=Speak}&quot;&gt;&lt;/textblock&gt;
&lt;/grid&gt;
</pre>
<p>
 </p>
<p><span style="font-size:12pt">To simplify more you can leave off the Path and just use the following.<br />
</span></p>
<pre class="brush: xml; ">

&lt;textblock x:Name=&quot;CatSound&quot; Text=&quot;{Binding Speak}&quot;&gt;&lt;/textblock&gt;
</pre>
<p>
 </p>
<p><span style="font-size:12pt">Notice the TextBlock no longer needs a Source extension because it looks in the DataContext by default.  A reason to use the DataContext is child controls can also access this. When you add a binding to that control first it will check the current UserControl and if it can&#8217;t be found it will check the parents DataContext.  For example, let&#8217;s move the TextBlock into a separate user control called CatControl.  Then we could get the same result as above using this.<br />
</span></p>
<pre class="brush: xml; ">

&lt;grid x:Name=&quot;LayoutRoot&quot; DataContext=&quot;{Binding Source={StaticResource ViewModel}}&quot;&gt;
        &lt;control :CatControl&gt;&lt;/control&gt;
&lt;/grid&gt;
</pre>
<p>
 </p>
<p><span style="font-size:12pt">Instead of using the Static Resource you can set the DataContext in C# as long as the control is initialized by doing the following.<br />
</span></p>
<pre class="brush: c#; ">

public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            DataContext = new Cat { Speak = &quot;meow in C#&quot; };
        }
    }
</pre>
<p> </p>
<p><span style="font-size:12pt">The binding syntax also supports drilling into properties of properties using dot notation.<br />
</span></p>
<pre class="brush: xml; ">

&lt;textblock x:Name=&quot;CatActivity&quot; Text=&quot;{Binding CatActivity.Scratch}&quot;&gt;&lt;/textblock&gt;
</pre>
<p><img src="http://jasonrowe.com/uploaded_images/051510_0248_Silverlight1.png" alt=""/><span style="font-size:12pt"><br />
		</span></p>
<pre class="brush: c#; ">

var activity = new CatActivity(){Scratch=&quot;scratchy&quot;};
DataContext = new Cat { Speak = &quot;meow in C#&quot;, CatActivity = activity };
</pre>
<p>
 </p>
<p><span style="font-size:16pt; text-decoration:underline"><strong>Binding with Notification and Dependency Properties<br />
</strong></span></p>
<p>
 </p>
<p><span style="font-size:12pt">An example where binding, notifications, and dependency properties show their power is when you need to make multiple Async web requests which have dependencies.<br />
</span></p>
<p><img src="http://jasonrowe.com/uploaded_images/051510_0248_Silverlight2.png" alt=""/><span style="font-size:12pt"><br />
		</span></p>
<p>
 </p>
<p><span style="font-size:12pt">To use notifications you need to inherit from <strong>INotifyPropertyChanged</strong>.  Then you can setup properties that will notify a binding when they change. For example, to update the quote we could have a notification property setup that would get updated by the request callback.<br />
</span></p>
<pre class="brush: c#; ">

        private Quote _quote;
        public Quote Quote
        {
            get { return _quote; }
            set
            {
                _quote = value;
                NotifyPropertyChanged(&quot;Quote&quot;);
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
</pre>
<pre class="brush: xml; ">

&lt;textblock x:Name=&quot;Price&quot; Text=&quot;{Binding Quote.Price}&quot;/&gt;
&lt;textblock x:Name=&quot;Price&quot; Text=&quot;{Binding Quote.PercentChange }&quot;/&gt;
</pre>
<p> </p>
<p><span style="font-size:12pt">For the Chart State we can setup a dependency property that will change the chart user control as needed. In this case we do some drawing and background changes.<br />
</span></p>
<pre class="brush: c#; ">

public static readonly DependencyProperty ChartStateProperty = DependencyProperty.Register(
            &quot;ChartState&quot;,
            typeof(StateIndicator),
            typeof(LineChartControl),
            new PropertyMetadata(StateIndicator.NoChange, OnChartStateChanged));

        private static void OnChartStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var lineChart = (LineChartControl)d;
            lineChart.CreateStateBackground((StateIndicator)e.NewValue);
            lineChart.ChangeLineColor((StateIndicator)e.NewValue);
        }
</pre>
<p>
 </p>
<p><span style="font-size:12pt">For a simpler example of notification binding we can go back to the cat example. Let&#8217;s setup the notification.<br />
</span></p>
<pre class="brush: c#; ">

  public class Cat : INotifyPropertyChanged
    {
        public string Speak { get; set; }

        private CatActivity _catActivity;
        public CatActivity CatActivity
        {
            get { return _catActivity; }
            set
            {
                _catActivity = value;
                NotifyPropertyChanged(&quot;CatActivity&quot;);
            }
        }

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

         public event PropertyChangedEventHandler PropertyChanged;

     }
</pre>
<p>
 </p>
<p><span style="font-size:12pt">Then let&#8217;s make a button and a few fields to bind to the CatActivity property.  Don&#8217;t take this as good coding practice. This is just a simplistic example to show how the notifications can be triggered.<br />
</span></p>
<pre class="brush: c#; ">

        public Cat MyCat { get; set; }
        public MainPage()
        {
            InitializeComponent();

            var activity = new CatActivity(){Scratch=&quot;scratchy&quot;, Run=&quot;scramble&quot;};
            MyCat = new Cat { Speak = &quot;meow in C#&quot;, CatActivity = activity };
            DataContext = MyCat;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var newActivity = new CatActivity() { Scratch = &quot;scratchy again&quot;, Run = &quot;scramble again too&quot; };
            MyCat.CatActivity = newActivity;
        }
</pre>
<p>
 </p>
<p>When you click the button the following bindings will show &#8220;scratch again&#8221; and &#8220;scramble again too&#8221;.</p>
<pre class="brush: xml; ">

&lt;stackpanel&gt;
    &lt;button Click=&quot;Button_Click&quot;&gt;&lt;/button&gt;
    &lt;textblock x:Name=&quot;CatSound&quot; Text=&quot;{Binding Speak}&quot;&gt;&lt;/textblock&gt;

    &lt;textblock x:Name=&quot;CatActivityScratch&quot; Text=&quot;{Binding CatActivity.Scratch}&quot;&gt;&lt;/textblock&gt;

    &lt;textblock x:Name=&quot;CatActivityRun&quot; Text=&quot;{Binding CatActivity.Run}&quot;&gt;&lt;/textblock&gt;
&lt;/stackpanel&gt;
</pre>
<p>
 </p>
<p>
 </p>
<p><span style="font-size:16pt; text-decoration:underline"><strong>SL4 and MVVM Links<br />
</strong></span></p>
<p>
 </p>
<ul>
<li>An early approach to MVVM on MSDN (<a href="http://msdn.microsoft.com/en-us/magazine/dd458800.aspx">http://msdn.microsoft.com/en-us/magazine/dd458800.aspx</a>)
</li>
<li>Prism MVVM SL and WPF <a href="http://compositewpf.codeplex.com/">http://compositewpf.codeplex.com/</a>
		</li>
<li>SL4 Command Binding MVVM <a href="http://www.silverlight.net/community/samples/silverlight-samples/command-binding-in-silverlight-4-35238/">http://www.silverlight.net/community/samples/silverlight-samples/command-binding-in-silverlight-4-35238/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/05/14/silverlight-binding-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight  Drag and Drop with RX</title>
		<link>http://jasonrowe.com/2010/04/02/silverlight-drag-and-drop-with-rx/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=silverlight-drag-and-drop-with-rx</link>
		<comments>http://jasonrowe.com/2010/04/02/silverlight-drag-and-drop-with-rx/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 06:08:49 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[rx]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1131</guid>
		<description><![CDATA[I highly recommend watching this video for the recently released RX extensions. It shows a walk through of implementing drag and drop in WPF. I took the same code and converted it to Silverlight for a fun exercise. The major &#8230; <a href="http://jasonrowe.com/2010/04/02/silverlight-drag-and-drop-with-rx/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I highly recommend watching this <a href="http://channel9.msdn.com/posts/J.Van.Gogh/Writing-your-first-Rx-Application/">video </a> for the recently released RX extensions. It shows a walk through of implementing drag and drop in WPF. I took the same code and converted it to Silverlight for a fun exercise.</p>
<p>The major differences are the Mouse event names are different and you need to use a dispatcher to avoid cross thread issues. Check the Rx forums for more recent and efficient ways to do this for use in production code.</p>
<p>You will also need to add the System.CoreEx, System.Observable, and System.Reactive .Net references.</p>
<p>[raw]</p>
<pre class="brush: c#; ">

// Observe MouseMove Events &lt;!--

var mouseMove = from evt in Observable.FromEvent&lt;mouseeventargs&gt;(this, &quot;MouseMove&quot;)
select evt.EventArgs.GetPosition(this);

// Observe Mouse LeftButtonUp Event --&gt; // &lt;!--

var mouseUp = from evt in Observable.FromEvent&lt;mousebuttoneventargs&gt;(this, &quot;MouseLeftButtonUp&quot;)
select evt.EventArgs.GetPosition(this);

// Observe MouseLeftButtonDown Event --&gt; &lt;!--

var mouseDown = from evt in Observable.FromEvent&lt;mousebuttoneventargs&gt;(this, &quot;MouseLeftButtonDown&quot;)
select evt.EventArgs.GetPosition(this);

// Calculate Movement and Display --&gt;

var q = from start in mouseDown
        from delta in mouseMove.StartWith(start).TakeUntil(mouseUp)
            .Let(mm =&gt; mm.Zip(mm.Skip(1), (prev, cur) =&gt;
                new { X = cur.X - prev.X, Y = cur.Y - prev.Y }))
        select delta;

q.Subscribe(value =&gt; textblock.Dispatcher.BeginInvoke(() =&gt;
{
  Canvas.SetLeft(image,Canvas.GetLeft(image) + value.X);
  Canvas.SetTop(image,Canvas.GetTop(image) + value.Y);
}));
</pre>
<p>[/raw]</p>
<p>For a better explanation of this code check out <a href="http://streaming.ndc2010.no/tcs/?id=2C3F6822-1694-48A6-9C49-8B3E3D4C6CE5">John Skeets RX video at NDC 2010</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/04/02/silverlight-drag-and-drop-with-rx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>System.Reactive IScheduler Hello World</title>
		<link>http://jasonrowe.com/2010/02/08/system-reactive-ischeduler-hello-world/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=system-reactive-ischeduler-hello-world</link>
		<comments>http://jasonrowe.com/2010/02/08/system-reactive-ischeduler-hello-world/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 23:16:14 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=987</guid>
		<description><![CDATA[I&#8217;ve been following the Reactive Extensions work on blogs, podcasts and forums. It sounds and looks amazing. The icing on the cake is Bart De Smet is going to be involved and it uses the new Parallel framework (TPL). Photo &#8230; <a href="http://jasonrowe.com/2010/02/08/system-reactive-ischeduler-hello-world/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been following the <a href="http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx">Reactive Extensions</a> work on <a href="http://blogs.msdn.com/rxteam/default.aspx">blogs</a>, <a href="http://www.hanselminutes.com/default.aspx?showID=216">podcasts</a> and <a href="http://social.msdn.microsoft.com/Forums/en-US/rx/threads">forums</a>. It sounds and looks amazing. The icing on the cake is <a href="http://community.bartdesmet.net/blogs/bart/archive/2010/01/10/2010-a-personal-change-putting-my-head-in-the-cloud.aspx">Bart De Smet</a> is going to be involved and it uses the new <a href="http://msdn.microsoft.com/en-us/concurrency/default.aspx">Parallel framework (TPL)</a>.</p>
<p>Photo of cake icing to make some odd point.<br />
<img src="http://jasonrowe.com/wp-content/uploads/2010/02/cake_icing.jpg" alt="" title="cake_icing" width="300" height="200" class="alignnone size-full wp-image-1003" /></p>
<p>After watching this great video <a href="http://blogs.msdn.com/rxteam/archive/2009/12/18/controlling-concurrency-in-rx.aspx">Controlling concurrency in Rx</a> on the RX team blog. I was inspired to start trying out the scheduler. Below are my basic code snippets that would be the equivalent of a hello world.</p>
<p>The first code snippet below uses the &#8220;Now&#8221; and &#8220;Later&#8221; schedulers that are provided. They follow this pattern respectively. <code>Schedule(Action); Schedule(Action, TimeSpan);</code>.</p>
<pre class="brush: c#; ">

 static void Main(string[] args)
        {
            var timespan = new TimeSpan(0, 0, 5);

            using (Scheduler.Later.Schedule(DoSomeActionLater, timespan))
            {
                using (Scheduler.Now.Schedule(DoSomeAction))
                {
                    Console.WriteLine(&quot;type q to quit&quot;);

                    while (Console.ReadLine() != &quot;q&quot;)
                    {
                        Thread.Sleep(1000);
                        Console.WriteLine(&quot;...&quot;);
                    }

                }
            }
        }

        public static void DoSomeActionLater()
        {
            Console.WriteLine(&quot;Later&quot;);
        }

        public static void DoSomeAction()
        {
            Console.WriteLine(&quot;Now&quot;);
        }
</pre>
<p>This will give you some output similar to this.<br />
<a href="http://jasonrowe.com/wp-content/uploads/2010/02/now_laterV21.png"><img src="http://jasonrowe.com/wp-content/uploads/2010/02/now_laterV21.png" alt="" title="now_laterV2" width="429" height="196" class="alignnone size-full wp-image-1015" /></a></p>
<p>The next snippet uses fixed point recursive scheduling. It follows this format <code>Schedule(Action<Action(TimeSpan)>,TimeSpan)</code></p>
<pre class="brush: c#; ">

        static void Main(string[] args)
        {
            var timespan = new TimeSpan(0, 0, 5);
            var scheduler = Scheduler.Default;

            using (scheduler.Schedule(Self =&gt;
               {
                   Console.WriteLine(&quot;recursive&quot;);
                   Self(timespan);

               }, timespan))
            {

                Console.WriteLine(&quot;type q to quit&quot;);
                while (Console.ReadLine() != &quot;q&quot;)
                {
                    Thread.Sleep(1000);
                    Console.WriteLine(&quot;...&quot;);
                }
            }
        }
</pre>
<p>Here is the result from the recursive scheduler.</p>
<p><a href="http://jasonrowe.com/wp-content/uploads/2010/02/recursiveV21.png"><img src="http://jasonrowe.com/wp-content/uploads/2010/02/recursiveV21.png" alt="" title="recursiveV2" width="413" height="340" class="alignnone size-full wp-image-1014" /></a></p>
<p>In the video on IScheduler, it&#8217;s mentioned that a scheduler could be written to abstract away time. On CodePlex you can find a simple implementation of a virtual time scheduler <a href="http://rxpowertoys.codeplex.com/wikipage?title=TimeMachineScheduler&#038;referringTitle=Home">TimeMachineScheduler</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2010/02/08/system-reactive-ischeduler-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity Framework &#8211; Code Only Looking Good (part 2)</title>
		<link>http://jasonrowe.com/2009/12/22/entity-framework-code-only-looking-good-part-2/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=entity-framework-code-only-looking-good-part-2</link>
		<comments>http://jasonrowe.com/2009/12/22/entity-framework-code-only-looking-good-part-2/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 05:19:53 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Entity Framework]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=855</guid>
		<description><![CDATA[Update: CTP3 is now available. This sample project below works fine with the new version but I have written a new post and sample project with some enhancements. In my initial post I tried out the &#8220;Code First&#8221; methodology of &#8230; <a href="http://jasonrowe.com/2009/12/22/entity-framework-code-only-looking-good-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><b>Update: CTP3 is now available. This sample project below works fine with the new version but I have written a new <a href="http://jasonrowe.com/2010/07/12/ef-ctp3-code-first-and-castle-windsor/">post and sample project</a> with some enhancements. </b></p>
<p>In my initial <a href="http://jasonrowe.com/2009/12/11/entity-framework-code-only/">post</a> I tried out the &#8220;Code First&#8221; methodology of Entity Framework. Taking the code only experiment a step further, I built a sample WCF service that queries and updates a table for holidays. You can browse and download the project via <a href="http://github.com/JasonRowe/EF-CTP2-HolidayService/archives/master">github</a>.</p>
<p>The console application &#8220;HolidayService.GenerateSchema&#8221; is very similar to the first post. It&#8217;s used to create the initial sqlexpress database and put in some initial test data. I did try out a simple configuration using some <a href="http://blogs.msdn.com/alexj/archive/2009/10/14/code-only-best-practices.aspx">best practices from this site</a>.
</p>
<p>The WCF service has two methods. </p>
<p><code><br />
    [ServiceContract]<br />
    public interface IHolidays<br />
    {<br />
        [OperationContract]<br />
        IList<holiday> GetHolidayDetails(DateTime startDate, DateTime endDate);</p>
<p>        [OperationContract]<br />
        int AddHolidayDetails(DateTime date, string name);<br />
    }<br />
</holiday></code></p>
<p>
In the HolidayService I created a HolidayManager class for CRUD operations. It uses a GlobalContext class to build an EF HolidayModel ObjectContext. For example, this is what that GetHolidays method looks like in the manager.
</p>
<p><code><br />
  using (holidayContext)<br />
  {<br />
     var holidayQueryResult = (from h in holidayContext.Holidays<br />
     where h.HolidayDate < endDate &#038; h.HolidayDate > startDate select h);</p>
<p>     foreach (var item in holidayQueryResult)<br />
     {<br />
          holidays.Add(item);<br />
     }<br />
  }<br />
</code></p>
<p>
In the GlobalContext class, is where my simple project started to feel some pain. It doesn&#8217;t feel right to be using a concrete version of the HolidayModel in the ContextBuilder which returns the ObjectContext. I also don&#8217;t like that the sql connection string and connection are all in this class. In another post, I&#8217;ll use some of the suggestions below to try to make this area more flexible.
</p>
<p><code><br />
var builder = new ContextBuilder<holidaymodel>();<br />
builder.Configurations.Add(new HolidayConfiguration());<br />
var connStr = ConfigurationManager.ConnectionStrings["UserDBConn"].ConnectionString;<br />
var connection = new SqlConnection(connStr);<br />
return builder.Create(connection);<br />
</holidaymodel></code></p>
<p>
Since this is a small project I didn&#8217;t go any further to clean up the GlobalContext class. I&#8217;ll leave that for next time I look into code only. Below are some links which investigate managing ObjectContext, dynamic models, and using EF in a business architecture.
</p>
<ol>
<li><a href="http://dotnetslackers.com/articles/ado_net/managing-entity-framework-objectcontext-lifespan-and-scope-in-n-layered-asp-net-applications.aspx">Managing Entity Framework ObjectContext</a></li>
<li><a href="http://blogs.msdn.com/alexj/archive/2009/11/09/tip-42-how-to-create-a-dynamic-model-using-code-only.aspx">how to create a dynamic model using code only</a></li>
<li><a href="http://daniel.wertheim.se/2009/11/13/entity-framework-4-part-4-autoregister-entitymappings/">Daniel Wertheim &#8211; EfEntityStore</a></li>
<li><a href="http://daniel.wertheim.se/2009/12/20/updates-to-putting-entity-framework-4-to-use-in-a-business-architecture/">Putting Entity framework 4 to use in a business architecture</a></li>
<li><a href="http://blogs.taiga.nl/martijn/tag/entity-framework/">Repository implementation &#8211; Entity Framework 4.0: a fresh start </a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2009/12/22/entity-framework-code-only-looking-good-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
