<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
      <channel>
        <title>Gabriel Bogéa Perez</title>
        <link>http://www.gbogea.com/</link>
        <description>
          This is the syndication feed for my blog.
        </description>
  
        <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/gbogea" type="application/rss+xml" /><item>
          <title>How to keep two ScrollViewers in Sync in WPF</title>
          <description>&lt;p&gt;As I got to know WPF, one of the features that I really like was the ability to bind the value of one control to the value of another one. Well, the other day I had a situation where I had 2 &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.aspx"&gt;ScrollViewers &lt;/a&gt;side by side and I wanted to the two of them to be in sync. So, if I used the scrollbar one the left one I'd like the one on the right to scroll by the same increment. My first thought was then to bind the value of the offset of the scrollbars, that would be simple right? Not. The offset property is readonly. The way around this is really simple, you need you use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.scrollchangedevent.aspx"&gt;ScrollChanged &lt;/a&gt;event and in that event you use the method &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.scrolltoverticaloffset.aspx"&gt;ScrollToVerticalOffset &lt;/a&gt;to move the ScrollBar of the other ScrollViewer.&lt;/p&gt;
&lt;p&gt;Here is an example where I have a window with two ScrollViewers, each one has a ListBox with 7 items inside. As you scroll on the left side scroll viewer to see all the items in the ListBox you will notice that the ScrollViewer on the right will follow.&lt;/p&gt;
&lt;pre class="brush: xhtml" title="code"&gt;
&amp;lt;Window x:Class=&amp;quot;WpfScrollbarSync.Window1&amp;quot;
    xmlns=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    xmlns:x=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;
    Title=&amp;quot;Window1&amp;quot; Height=&amp;quot;100&amp;quot; Width=&amp;quot;300&amp;quot;&amp;gt;
    &amp;lt;Grid&amp;gt;
        &amp;lt;Grid.ColumnDefinitions&amp;gt;
            &amp;lt;ColumnDefinition Width=&amp;quot;1*&amp;quot; /&amp;gt;
            &amp;lt;ColumnDefinition Width=&amp;quot;1*&amp;quot; /&amp;gt;
        &amp;lt;/Grid.ColumnDefinitions&amp;gt;
        &amp;lt;ScrollViewer Grid.Column=&amp;quot;0&amp;quot; Name=&amp;quot;scrollViewerLeft&amp;quot; ScrollChanged=&amp;quot;scrollViewerLeft_ScrollChanged&amp;quot;&amp;gt;
            &amp;lt;ListBox&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;1&amp;lt;/ListBoxItem&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;2&amp;lt;/ListBoxItem&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;3&amp;lt;/ListBoxItem&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;4&amp;lt;/ListBoxItem&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;5&amp;lt;/ListBoxItem&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;6&amp;lt;/ListBoxItem&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;7&amp;lt;/ListBoxItem&amp;gt;
            &amp;lt;/ListBox&amp;gt;
        &amp;lt;/ScrollViewer&amp;gt;
        &amp;lt;ScrollViewer Grid.Column=&amp;quot;1&amp;quot; Name=&amp;quot;scrollViewerRight&amp;quot;&amp;gt;
            &amp;lt;ListBox&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;1&amp;lt;/ListBoxItem&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;2&amp;lt;/ListBoxItem&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;3&amp;lt;/ListBoxItem&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;4&amp;lt;/ListBoxItem&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;5&amp;lt;/ListBoxItem&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;6&amp;lt;/ListBoxItem&amp;gt;
                &amp;lt;ListBoxItem&amp;gt;7&amp;lt;/ListBoxItem&amp;gt;
            &amp;lt;/ListBox&amp;gt;
        &amp;lt;/ScrollViewer&amp;gt;
    &amp;lt;/Grid&amp;gt;
&amp;lt;/Window&amp;gt;&lt;/pre&gt;
&lt;p&gt;And here is the codebehind:&lt;/p&gt;
&lt;pre class="brush: csharp" title="code"&gt;
public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();
    }

    private void scrollViewerLeft_ScrollChanged(object sender, ScrollChangedEventArgs e)
    {
        scrollViewerRight.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
    }
}
&lt;/pre&gt;
&lt;p&gt;I hope this can save someone one minute or two. :-)&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gbogea/~4/pDamYHkl61U" height="1" width="1"/&gt;</description>
          <link>http://feedproxy.google.com/~r/gbogea/~3/pDamYHkl61U/how-to-keep-two-scrollviewers-in-sync-in-wpf</link>
          <author>Gabriel Perez</author>
          <pubDate>
             Wed, 08 Jul 2009 00:00:00 GMT
           </pubDate>
        <feedburner:origLink>http://www.gbogea.com//2009/07/08/how-to-keep-two-scrollviewers-in-sync-in-wpf</feedburner:origLink></item>
  
        <item>
          <title>Windows 7 x64 and Oracle Client</title>
          <description>&lt;p&gt;I installed my Windows 7 x64 this weekend and so far everything is great. Much better than when I was running on Vista.&lt;/p&gt;
&lt;p&gt;I thought I had run into my first problem with 7 when was setting up my Oracle connection. I installed the Oracle Client 11g x64 successfully, I could even connect to the database using SqlPlus. My Visual Studio on the other hand disagreed. When I tried to configure a connection to my Oracle server I got the following error:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Exception: Attempt to load Oracle client libraries threw &lt;br /&gt;
BadImageFormatException. This problem will occur when running in 64 &lt;br /&gt;
bit mode with the 32 bit Oracle client components installed&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This was weird, after all I could connect to the database through SqlPlus, right? The problem is that VS2008 is 32 bit and as such it needs a 32 Oracle Client in order to connect to the db. When I installed the 32 bit client VS was able to connect to the db on the spot. So the only problem I had with Windows 7 so far had nothing to do with Windows 7, in fact you would run into the same situation in any other 64 bit version of Windows.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gbogea/~4/pILNhL9iZ9Y" height="1" width="1"/&gt;</description>
          <link>http://feedproxy.google.com/~r/gbogea/~3/pILNhL9iZ9Y/windows-7-x64-and-oracle-client</link>
          <author>Gabriel Perez</author>
          <pubDate>
             Tue, 07 Jul 2009 00:00:00 GMT
           </pubDate>
        <feedburner:origLink>http://www.gbogea.com//2009/07/07/windows-7-x64-and-oracle-client</feedburner:origLink></item>
  
        <item>
          <title>Converting Base10 to Base26</title>
          <description>&lt;p&gt;There is a post I answered on the asp.net forums I thought was really interesting because it reminded me of my college times. Actually I'm pretty sure that the guy who posted the question was trying to get an answer to his homework, but it doesn't matter, I had fun doing it :-).  The problem was to do an ascending sequence using the alphabet (which is a Base26). Something like: A,B,C...Z,AA,AB,AC...AZ,BA,BB,BC...BZ and so on. Well the easiest way to do this is to convert our regular Base10 numbers to Base26 because using Base10 we can do a plain for loop and cout up to the number we want and while doing the loop we can convert the Base10 to Base26. Here is the algorithm:&amp;nbsp;&lt;/p&gt;
&lt;pre title="code" class="brush: csharp"&gt;
        public static string NumberToString(int value)
        {
            StringBuilder sb = new StringBuilder();
            
            do
            {
                value--;
                int remainder = 0;
                value = Math.DivRem(value, 26, out remainder);
                sb.Insert(0, Convert.ToChar('A' + remainder));
                
            } while (value &amp;gt; 0);

            return sb.ToString();
        }&lt;/pre&gt;
&lt;p&gt;I know this isn't very useful for everyday programming but it was fun to remember the time I was still in college solving this kind of problem. It was a really fun exercise.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gbogea/~4/YKwkLXR18OY" height="1" width="1"/&gt;</description>
          <link>http://feedproxy.google.com/~r/gbogea/~3/YKwkLXR18OY/converting-base10-to-base26</link>
          <author>Gabriel Perez</author>
          <pubDate>
             Mon, 29 Jun 2009 00:00:00 GMT
           </pubDate>
        <feedburner:origLink>http://www.gbogea.com//2009/06/29/converting-base10-to-base26</feedburner:origLink></item>
  
        <item>
          <title>Typed Convert using Generics</title>
          <description>&lt;p&gt;Last night I answerd a interesting question on the Asp.Net Forums that I thought is worth a post. The objective was to create a method using Generics that could get a value from the Session only instead of returning a Object it would return the value in the type defined in the generic method. Just to make the demonstration easier I'll use a Dictionary instead of the Session but it works just the same:&lt;/p&gt;
&lt;pre title="code" class="brush: csharp"&gt;
class TypeTest
{
    private static Dictionary&amp;lt;string, object&amp;gt; PretendSession = new Dictionary&amp;lt;string, object&amp;gt;();

    public static void Test()
    {
        PretendSession.Add(&amp;quot;int&amp;quot;, 10M);
        Console.Out.WriteLine(Get&amp;lt;int&amp;gt;(&amp;quot;int&amp;quot;));
    }

    public static T Get&amp;lt;T&amp;gt;(string theKey)
    {
        object aSessionObject = PretendSession[theKey];

        if (aSessionObject == null)
        {
            return default(T);
        }

        return (T) aSessionObject;
    }
}
&lt;/pre&gt;
&lt;p&gt;This code works well for most cases but you can get in trouble when you work with Value Types. Look at code that follows and to undestand the problems with boxing and unboxing value types:&lt;/p&gt;
&lt;pre title="code" class="brush: csharp"&gt;
 //doesn't work, need explicit cast 
int i = 10M; 

//now it's fine 
int i = (int)10M; 

//boxing and unboxing work fine 
object o = 10; 
int i = (int)o; 

//doesn't work 
object o = 10M; 
int i = (int)o;&lt;/pre&gt;
&lt;p&gt;When you know exactaly what is the type of you are putting inside the Session it all goes fine. When you don't know what type you are working with you need the help of the Convert class to convert the type before casting it. To do this we test if the object is of type ValueType and if it is, before casting it we use the ChangeType method of the Convert class to make sure that the object really contains the type we will try to cast it to.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre title="code" class="brush: csharp"&gt;
class TypeTest
{
    static Dictionary&amp;lt;string, object&amp;gt; PretendSession = new Dictionary&amp;lt;string, object&amp;gt;();

    public static void Test()
    {
        PretendSession.Add(&amp;quot;int&amp;quot;, 10M);
        Console.Out.WriteLine(Get&amp;lt;int&amp;gt;(&amp;quot;int&amp;quot;));
    }

    public static T Get&amp;lt;T&amp;gt;(string theKey)
    {
        object aSessionObject = PretendSession[theKey];

        if (aSessionObject == null)
        {
            return default(T);
        }

        if (aSessionObject is ValueType)
        {
            return (T)Convert.ChangeType(aSessionObject, typeof(T));
        }

        return (T)aSessionObject;
    }
}
&lt;/pre&gt;
&lt;p&gt;Now you should be safe to use your Get&amp;lt;T&amp;gt; method. Hope this can help other people that face this same issue.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gbogea/~4/rK1bg64yDPM" height="1" width="1"/&gt;</description>
          <link>http://feedproxy.google.com/~r/gbogea/~3/rK1bg64yDPM/typed-convert-using-generics</link>
          <author>Gabriel Perez</author>
          <pubDate>
             Thu, 14 May 2009 00:00:00 GMT
           </pubDate>
        <feedburner:origLink>http://www.gbogea.com//2009/05/14/typed-convert-using-generics</feedburner:origLink></item>
  
        <item>
          <title>Passed 70-547</title>
          <description>&lt;p&gt;Hey, I'm just writing to let my friend know that I have passed the 70-547 exam and now I'm an MCPD Web Developer.&lt;/p&gt;
&lt;p&gt;I have to say that the test was way easier than I thought. I think it was the easiest Microsoft test I have ever taken.&lt;/p&gt;
&lt;p&gt;If you are asking why I still took a .NET 2.0 exam the reason is simple. I had already bought all the books last year. I was supposed to take the test last October but I had to help out at work doing some long shifts to deliver a product that was sold before we expected. Go news for them and a lot of work for me :-). Not to worry I really like the guys I work for and the system is kind of a son to me so I also had fun. Now that it's over I'm back to my plans.&lt;/p&gt;
&lt;p&gt;Now I'm in the process of getting my MCT (Microsoft Certified Trainer).&lt;/p&gt;
&lt;p&gt;I'll keep you guys posted on how it goes.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gbogea/~4/Md_pUVKRSIU" height="1" width="1"/&gt;</description>
          <link>http://feedproxy.google.com/~r/gbogea/~3/Md_pUVKRSIU/passed-70-547</link>
          <author>Gabriel Perez</author>
          <pubDate>
             Mon, 11 May 2009 00:00:00 GMT
           </pubDate>
        <feedburner:origLink>http://www.gbogea.com//2009/05/11/passed-70-547</feedburner:origLink></item>
  
        <item>
          <title>ELMAH: Error logging doesn't get any simpler</title>
          <description>&lt;p&gt;&lt;a href="http://code.google.com/p/elmah/"&gt;ELMAH &lt;/a&gt;stands for Error Logging Modules and Handlers. I don't love the name but everything else about it is great!! In it's site it is described as:&lt;/p&gt;
&lt;p&gt;&amp;quot;ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running &lt;a href="http://www.asp.net/" rel="nofollow"&gt;ASP.NET&lt;/a&gt; web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.&amp;quot;&lt;/p&gt;
&lt;p&gt;I'm using &lt;a href="http://speakoutblog.codeplex.com/"&gt;this blog&lt;/a&gt; as I write it and if I had to classify it I'd say it is a &lt;em&gt;pre pre alpha release&lt;/em&gt; not suitable for anyone else but me. The only use I see for other people right now is to look around the code (what should be quick). Given my choice to put the application online in this early stage it seamed pretty obvious that that I needed to start logging the errors my users are getting so that I can work on them as soon as possible. As usual I was deciding between using &lt;a href="http://www.nlog-project.org"&gt;NLog &lt;/a&gt;or &lt;a href="http://logging.apache.org/log4net/index.html"&gt;Log4Net&lt;/a&gt; when I saw a new &lt;a href="http://www.hanselman.com/blog/ELMAHErrorLoggingModulesAndHandlersForASPNETAndMVCToo.aspx"&gt;post by Scott Hanselman&lt;/a&gt; talking about ELMAH.&lt;/p&gt;
&lt;p&gt;As usual Scott's post saved me a lot of time! Setting up ELMAH was really as simple as he said. In a matter of minutes I was logging all errors in my application. Now I can sleep well knowing that every weekend I'll have a list of errors to work on :-)&lt;/p&gt;
&lt;p&gt;I highly recommend you use this in your application even if you are already using another logging framework. The cool thing about ELMAH is that if you missed something forgot to place logging on some part of your app, ELMAH won't. It will log every error you have and store it in XML, SQLServer, Oracle...&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gbogea/~4/i2Ehca-9Y2I" height="1" width="1"/&gt;</description>
          <link>http://feedproxy.google.com/~r/gbogea/~3/i2Ehca-9Y2I/elmah-error-logging-doesnt-get-any-simpler</link>
          <author>Gabriel Perez</author>
          <pubDate>
             Sun, 03 May 2009 00:00:00 GMT
           </pubDate>
        <feedburner:origLink>http://www.gbogea.com//2009/05/03/elmah-error-logging-doesnt-get-any-simpler</feedburner:origLink></item>
  
        <item>
          <title>Lessons Learned in Url Rewriting</title>
          <description>&lt;p&gt;When I decided to write my own blog and leave Mephisto one of the few requirements I felt were really important was to maintain the url pattern I was already using. My articles had url's like this:&lt;br /&gt;
&lt;br /&gt;
www.gbogea.com/year/month/day/permalink&lt;br /&gt;
&lt;br /&gt;
When I first looked up url rewriting in google I found a great &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx"&gt;article by ScottGu&lt;/a&gt; that really suited my needs. I'm using IIS7 on my develpment machine and I thought I was also using it on the hosting service I contracted. ScottGu's post shows a really simple way to do rewriting when using IIS7. All you need is the &lt;a href="http://urlrewriter.net/"&gt;UrlRewriter.Net module&lt;/a&gt; and a few configurations to your web.config.&lt;br /&gt;
Checkout SocottGu's post for the whole config, here I'll only show you the pattern I needed to be compatible with the articles url in Mephisto. Here it is: &lt;/p&gt;
&lt;pre class="brush: xhtml" title="code"&gt;
&amp;lt;rewrite url=&amp;quot;~/((19|20)\d\d)/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])/(.+)&amp;quot; to=&amp;quot;~/PostDetail.aspx?year=$1&amp;amp;amp;month=$3&amp;amp;amp;day=$4&amp;amp;amp;permalink=$5&amp;quot;/&amp;gt;&lt;/pre&gt;
&lt;p&gt;Once I did this everything worked fine. I had achieved my objective, or so I thought. The problem is that I found out later on that my hosting service was actually using IIS6 and to my sadness IIS6 doesn't do well with url's that do not have an extension. &lt;br /&gt;
&lt;br /&gt;
When I contacted my hosting they informed me that they had support for ISAPI Rewrite, which is alson discussed in Scott's post but sadly not in engough depth for my case. The configuration is also a lot more anoying then with UrlRewrite.Net. If you have to use ISAPI Rewrite my first recomendation is to get in touch with your hosting and find out if they have version 2 or 3 installed. It makes a great difference. In my case I had version 3 installed. Here are the steps I took to configure it:&lt;br /&gt;
&lt;br /&gt;
1 - Create a &amp;quot;.htaccess&amp;quot; file in the root or your web application.&lt;br /&gt;
&lt;br /&gt;
2 - In the file I've written the following code: &lt;/p&gt;
&lt;pre class="brush: csharp" title="code"&gt;
RewriteEngine on
RewriteBase /
RewriteRule ((19|20)\d\d)/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])/(.+)$ /PostDetail.aspx?year=$1&amp;amp;month=$3&amp;amp;day=$4&amp;amp;permalink=$5 [NC,L]&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
The rewrite rule is basically translating the pattern I'm using (www.gbogea.com/year/month/day/permalink) to the real pattern that the ASP.NET applcation understands (PostDetail.aspx?year=YYYY&amp;amp;month=MM&amp;amp;day=DD&amp;amp;permalink=WHATERVER).&lt;br /&gt;
&lt;br /&gt;
The options and the end are also very important. NC means Case Insensitive. L means that no other subsquent rule should be processed, it stops here. You will find a lot of examples that use an R (which means Redirect) however this was not suited to my case. The redirect would be done to the new URL and then the url shown in the browser would be the ASP.NET url and not mine.&lt;br /&gt;
&lt;br /&gt;
This usage was not easy to figure out. If you need any assistance on using ISAPIRewrite I can recomend this two links:&lt;br /&gt;
&lt;br /&gt;
Documentation: &lt;a href="http://www.helicontech.com/isapi_rewrite/doc/"&gt;http://www.helicontech.com/isapi_rewrite/doc/&lt;/a&gt;&lt;br /&gt;
Blog: &lt;a href="http://helicontech.blogspot.com/search/label/isapi_rewrite"&gt;http://helicontech.blogspot.com/search/label/isapi_rewrite&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Helicon's blog was the one that helped me the most. The have a post about common issues people have which is really to the point.&lt;br /&gt;
&lt;br /&gt;
Looking back at all the work I had it would probably be cheaper just to have my hosting plan upgraded to IIS7 but where would be the fun in that right? Joking aside, it's this kind of thing that make you learn, perhaps your client doesn't have the option to migrate to IIS7, then what would you do? Having said that, if you have the choice between using IIS 6 and 7 I would definitely go with 7 and avoid using ISAPI Rewrite altogether.&lt;br /&gt;
&lt;br /&gt;
If you want to have a closer look at my web.config or the .htaccess file you can look at the source code for this blog at &lt;a href="http://speakoutblog.codeplex.com/"&gt;speakoutblog.codeplex.com&lt;/a&gt;. At this time there is no realease version yet but you can go to the source code and download any commit you want.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gbogea/~4/ul-t5NtiOlA" height="1" width="1"/&gt;</description>
          <link>http://feedproxy.google.com/~r/gbogea/~3/ul-t5NtiOlA/lessons-learned-in-url-rewriting</link>
          <author>Gabriel Perez</author>
          <pubDate>
             Fri, 01 May 2009 00:00:00 GMT
           </pubDate>
        <feedburner:origLink>http://www.gbogea.com//2009/05/01/lessons-learned-in-url-rewriting</feedburner:origLink></item>
  
        <item>
          <title>Finally, the move is over!</title>
          <description>&lt;p&gt;Finally! After a few days my new blog is alive.&lt;/p&gt;
&lt;p&gt;I've been using Mephisto for a long time but I felt it was time to change. Mephisto is writen in Ruby On Rails and while I really like Rails I really needed an Blog engine writen in ASP.NET. There were many excelent options like:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.subtextproject.com"&gt;Subtext&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.codeplex.com/dasBlog"&gt;dasBlog&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogengine.codeplex.com"&gt;BlogEngine.Net&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;All of the above are great blog engines. They are used by most of the community. So which one did I chose? None!&lt;/p&gt;
&lt;p&gt;I decided to create my own blog engine. I know, I know...&amp;nbsp; Why?? Am I crazy? Do I want to take over the blog market? Nope!!! All I really wanted was a pet project that I could really use while allowing me to keep trying new stuff. A blog engine is something simple enough that I don't need to worry about the business rules. It's been done over and over and we use it everyday. It is also small enough that if I ever decide to throw all my code in the trash and start over with a different approach I easily could.&lt;/p&gt;
&lt;p&gt;For this adventure I created a project at Codeplex: &lt;span style="text-decoration: underline;"&gt;&lt;a href="http://speakoutblog.codeplex.com/"&gt;SpeakOutBlog&lt;/a&gt;.&lt;/span&gt; From now on SpeakOut is my sandbox, the place I'm going to try ideas and technologies that interest me. The good thing is that at the same time I'll have do something that works, otherwise my blog will go offline. I don't want to let my fans (my wife, dad and mom) down.&lt;/p&gt;
&lt;p&gt;On my next post I'll talk about the difficulties I had with URL Rewriting on my shared hosting. I hope that this project keeps giving me material for the blog.&lt;/p&gt;
&lt;p&gt;Oh, before I forget... I really want to thanks the guys that develop Subtext, dasBlog and BlogEngine.Net. Their code is really fun to play with and gave me many ideas to use in SpeakOut. I hope someday someone could look at my code and learn something interesting as I have learned from these guys code.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gbogea/~4/RqMuF2ny_5I" height="1" width="1"/&gt;</description>
          <link>http://feedproxy.google.com/~r/gbogea/~3/RqMuF2ny_5I/finally-the-move-is-over</link>
          <author>Gabriel Perez</author>
          <pubDate>
             Tue, 28 Apr 2009 00:00:00 GMT
           </pubDate>
        <feedburner:origLink>http://www.gbogea.com//2009/04/28/finally-the-move-is-over</feedburner:origLink></item>
  
        <item>
          <title>MVC Storefront: Migrating to the Entity Framework</title>
          <description>&lt;p&gt;The title of the post is actually misleading. A better title (although too long) would be: Migrating the Repository concept used in the &lt;span class="caps"&gt;MVC&lt;/span&gt; Storefront to the Entity Framework.&lt;/p&gt;
&lt;p&gt;Lately I&amp;rsquo;ve been playing more with the Entity Framework. The other day I was trying to replicate the way Rob Conery used the Repository Pattern in the &lt;span class="caps"&gt;MVC&lt;/span&gt; Storefront sample application and I was surprised to learn that the Entity Framework has some differences from &lt;span class="caps"&gt;LINQ&lt;/span&gt; to &lt;span class="caps"&gt;SQL&lt;/span&gt; that I did not expect.&lt;/p&gt;
&lt;p&gt;My first test was very simple. I wanted to get an IQueryable of Posts with it&amp;rsquo;s respective Comments attached. The StoreFront did this in a really clever and simple manner. The following code was supposed to work:&lt;/p&gt;
&lt;pre title="code" class="brush: csharp"&gt;
class BlogRepository
{
    SOEntities ctx = new SOEntities();

    public IQueryable&amp;lt;Comment&amp;gt; GetComments()
    {
        return from comment in ctx.Comments.Include(&amp;quot;Post&amp;quot;)
               select new Comment()
               {
                   CommentId = comment.CommentId,
                   Author = comment.Author,
                   Body = comment.Body,
                   PostId = comment.Post.PostId
               };
    }

    public IQueryable&amp;lt;Post&amp;gt; GetPosts()
    {
        var posts = from post in ctx.Posts
                    let comments = GetComments()
                    select new Post()
                           {
                               PostId = post.PostId,
                               Title = post.Title,
                               Body = post.Body,
                               Comments = comments.Where(x =&amp;gt; x.PostId == post.PostId)
                           };
        return posts;
    }
}

class Post
{
    public Guid PostId { get; set; }

    public string Title { get; set; }

    public string Body { get; set; }

    public IList&amp;lt;Comment&amp;gt; Comments { get; set; }
}

class Comment
{
    public Guid CommentId { get; set; }

    public Guid PostId { get; set; }

    public string Author { get; set; }

    public string Body { get; set; }

}

class Program 
{
static void Main(string[] args)
{
    BlogRepository rep = new BlogRepository();
    var posts = rep.GetPosts();
    posts = posts.Where(x =&amp;gt; x.Title.Contains(&amp;quot;MVC&amp;quot;));
    List&amp;lt;Post&amp;gt; postList = posts.ToList();
}
}&lt;/pre&gt;
&lt;p&gt;I get an error saying that Linq to Entities does not recognize the method GetComments().&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s not a bug, it&amp;rsquo;s is just the way the EF works. The method GetComments can&amp;rsquo;t be translated to anything in the provider. But why does it work with Linq to Sql you ask? Because it converts the Linq expression in a different way. Sorry but the post would be too long if I got into this subject.&lt;/p&gt;
&lt;p&gt;The way recommended by the EF team is you use the AsEnumerable() extension method, forcing the initial query to be executed and then you would be working with objects. Here is how I needed to change my code for this to work:&lt;/p&gt;
&lt;pre title="code" class="brush: csharp"&gt;
public IQueryable&amp;lt;Post&amp;gt; GetPosts()
{
    var posts = from post in ctx.Posts.AsEnumerable()
                let comments = GetComments()
                select new Post()
                       {
                           PostId = post.PostId,
                           Title = post.Title,
                           Body = post.Body,
                           Comments = comments.Where(x =&amp;gt; x.PostId == post.PostId)
                       };
    return posts.AsQueryable();
}
&lt;/pre&gt;
&lt;p&gt;This does work, but when ToList() method is called in the posts object, instead of filtering the posts in the sql code, all the posts are brought from the database and then they are filtered as objects. This is a work around but it&amp;rsquo;s not ideal.&lt;/p&gt;
&lt;p&gt;I have another work around, it also isn&amp;rsquo;t the ideal but it does work in the sense that it will apply the filter in the database.&lt;/p&gt;
&lt;pre title="code" class="brush: csharp"&gt;
public IQueryable&amp;lt;Post&amp;gt; GetPosts()
{
    var comments = GetComments();
    var posts = from post in ctx.Posts
                select new Post()
                       {
                           PostId = post.PostId,
                           Title = post.Title,
                           Body = post.Body,
                           CommentsQry = comments.Where(x =&amp;gt; x.PostId == post.PostId)
                       };
    return posts;
}

class Post
{
    public Guid PostId { get; set; }

    public string Title { get; set; }

    public string Body { get; set; }

    public IList&amp;lt;Comment&amp;gt; Comments { get; set; }

    public IQueryable&amp;lt;Comment&amp;gt; CommentsQry
    {
        set { Comments = new LazyList&amp;lt;Comment&amp;gt;(value); }
    }
}
&lt;/pre&gt;
&lt;p&gt;The trick is that I introduced a IQueryable property in the Post class. This property receives an IQueryable and under the hood converts it to a LazyList and sets the Comments property. Doing this overcomes the limitation that the EF has in not letting you use constructors that take parameters in the EF code. It only allows parameterless constructors on the select projection.&lt;/p&gt;
&lt;p&gt;If you run this code you will see that the records are filtered in the database. The reason I still don&amp;rsquo;t consider this solution ideal is that I had to make a change to my model class and created a property that is not related to the business but rather to a limitation imposed by the framework. I still don&amp;rsquo;t see a way around this. If anyone has any suggestions please do leave them as comments.&lt;/p&gt;
&lt;p&gt;A very interesting post was written by &lt;a href="http://mosesofegypt.net/post/2008/08/31/LINQ-to-Entities-Workarounds-on-what-is-not-supported.aspx"&gt;Muhammad Mosa&lt;/a&gt; a while ago. It&amp;rsquo;s worth visiting his &lt;a href="http://mosesofegypt.net/post/2008/08/31/LINQ-to-Entities-Workarounds-on-what-is-not-supported.aspx"&gt;blog&lt;/a&gt; to checkout his idea.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gbogea/~4/_wpK8gC8FlY" height="1" width="1"/&gt;</description>
          <link>http://feedproxy.google.com/~r/gbogea/~3/_wpK8gC8FlY/mvc-storefront-migrating-to-the-entity-framework</link>
          <author>Gabriel Perez</author>
          <pubDate>
             Wed, 22 Apr 2009 00:00:00 GMT
           </pubDate>
        <feedburner:origLink>http://www.gbogea.com//2009/04/22/mvc-storefront-migrating-to-the-entity-framework</feedburner:origLink></item>
  
        <item>
          <title>Find and Replace using Regular Expressions within Visual Studio</title>
          <description>&lt;p&gt;Regular expressions can be a great addition to the Find and Replace  functionality within Visual Studio, specially when you want do do some  transformation on the text you are looking up. Lately I&amp;rsquo;m working on a simple  conversion class to transform some &lt;span class="caps"&gt;HTML&lt;/span&gt; into &lt;span class="caps"&gt;RTF&lt;/span&gt;. I got a list of special characters in &lt;span class="caps"&gt;HTML&lt;/span&gt; that I had to convert to the &lt;span class="caps"&gt;RTF&lt;/span&gt;  equivalent and for that I needed to create a dictionary. The values where listed  in a text document like this:&lt;/p&gt;
&lt;pre class="brush: csharp" title="code"&gt;
\'b0 \tab &amp;amp;deg;\par
\'b1 \tab &amp;amp;plusmn;\par
\'b2 \tab &amp;amp;sup2;\par
\'b3 \tab &amp;amp;sup3;\par
\'b4 \tab &amp;amp;acute;\par
\'b5 \tab &amp;amp;micro;\par
\'b6 \tab &amp;amp;para;\par
\'b7 \tab &amp;amp;middot;\par
\'b8 \tab &amp;amp;cedil;\par
\'b9 \tab &amp;amp;sup1;\par
\'ba \tab &amp;amp;ordm;\par
\'bb \tab &amp;amp;raquo;\par
\'bc \tab &amp;amp;frac14;\par
\'bd \tab &amp;amp;frac12;\par
\'be \tab &amp;amp;frac34;\par
&lt;/pre&gt;
&lt;p&gt;And I needed to create a dictionary with the key being the &lt;span class="caps"&gt;HTML&lt;/span&gt; code (third column) and the &lt;span class="caps"&gt;RTF&lt;/span&gt;  code (first column) the value. Like this:&lt;/p&gt;
&lt;pre class="brush: csharp" title="code"&gt;
Dictionary&amp;lt;string, string&amp;gt; charsMapping = 
    new Dictionary&amp;lt;string, string&amp;gt;();
charsMapping.Add(&amp;quot;&amp;amp;euro;&amp;quot;, @&amp;quot;\'80&amp;quot;);
&lt;/pre&gt;
&lt;p&gt;Here is the expression to find the matches within Visual Studio: __  {\\&amp;rsquo;:a:a}{.&lt;ins&gt;}{&amp;amp;:a&lt;/ins&gt;;}{\\par}&lt;/p&gt;
&lt;p&gt;&lt;i&gt;Each pair of { } is a group to be matched. The difference is that the usual  \w (letters or numbers) is :a. In my expression I have four groups the fist is  the match for the &lt;span class="caps"&gt;RTF&lt;/span&gt; character and the third is the  match for the &lt;span class="caps"&gt;HTML&lt;/span&gt; code. Knowing that the Replace  expression is as follows: __charsMapping.Add(&amp;rdquo;\3&amp;rdquo;, @&amp;rdquo;\1&amp;rdquo;);&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;Here is how it would look like in VS:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://wwww.gbogea.com/upload/regexFindReplace.jpg" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;Doing this is much easier then creating the dictionary by hand of even  writing a console app to do the replace. Sure I could have used some other text  tool to do the same but it wouldn&amp;rsquo;t be as much fun as figuring out how to do it  in VS.&lt;/p&gt;
&lt;p&gt;Here is the final output:&lt;/p&gt;
&lt;pre class="brush: csharp" title="code"&gt;
Dictionary&amp;lt;string, string&amp;gt; charsMapping = 
    new Dictionary&amp;lt;string, string&amp;gt;();
charsMapping.Add(&amp;quot;&amp;amp;deg;&amp;quot;, @&amp;quot;\'b0&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;plusmn;&amp;quot;, @&amp;quot;\'b1&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;sup2;&amp;quot;, @&amp;quot;\'b2&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;sup3;&amp;quot;, @&amp;quot;\'b3&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;acute;&amp;quot;, @&amp;quot;\'b4&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;micro;&amp;quot;, @&amp;quot;\'b5&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;para;&amp;quot;, @&amp;quot;\'b6&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;middot;&amp;quot;, @&amp;quot;\'b7&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;cedil;&amp;quot;, @&amp;quot;\'b8&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;sup1;&amp;quot;, @&amp;quot;\'b9&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;ordm;&amp;quot;, @&amp;quot;\'ba&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;raquo;&amp;quot;, @&amp;quot;\'bb&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;frac14;&amp;quot;, @&amp;quot;\'bc&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;frac12;&amp;quot;, @&amp;quot;\'bd&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;frac34;&amp;quot;, @&amp;quot;\'be&amp;quot;);
charsMapping.Add(&amp;quot;&amp;amp;iquest;&amp;quot;, @&amp;quot;\'bf&amp;quot;);
&lt;/pre&gt;
&lt;p&gt;Of course the number of characters was much bigger but it doesn&amp;rsquo;t matter here.  If you need more info on regular expressions you might want to check out the &lt;a href="http://www.regular-expressions.info/"&gt;Regular-Expressions.info&lt;/a&gt; site,  they have a lot of good info on the subject. There are some specifics to using  regular expressions on VS so you need to make sure to visit &lt;a href="http://msdn.microsoft.com/en-us/library/2k3te2cs(VS.80).aspx"&gt;&lt;span class="caps"&gt;MSDN&lt;/span&gt; Reference&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gbogea/~4/JZkyBGOev0A" height="1" width="1"/&gt;</description>
          <link>http://feedproxy.google.com/~r/gbogea/~3/JZkyBGOev0A/find-and-replace-using-regular-expressions-within-visual-studio</link>
          <author>Gabriel Perez</author>
          <pubDate>
             Fri, 03 Apr 2009 00:00:00 GMT
           </pubDate>
        <feedburner:origLink>http://www.gbogea.com//2009/04/03/find-and-replace-using-regular-expressions-within-visual-studio</feedburner:origLink></item>
  
      </channel>
    </rss>
