<?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"
	>

<channel>
	<title>.Net Ramblings</title>
	<atom:link href="http://blog.yodersolutions.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.yodersolutions.com</link>
	<description></description>
	<pubDate>Fri, 11 Dec 2009 16:07:52 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>The Single Responsibility Principle</title>
		<link>http://blog.yodersolutions.com/2009/12/the-single-responsibility-principle/</link>
		<comments>http://blog.yodersolutions.com/2009/12/the-single-responsibility-principle/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 16:07:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.yodersolutions.com/2009/12/the-single-responsibility-principle/</guid>
		<description><![CDATA[The Single Responsibility Principle states that a class should only have one reason to change. Another possible title for this design principle would be the Single Reason to Change Principle.
Why is it important for a class to have a single reason to change and what are its benefits? One of the easiest ways to enhance [...]]]></description>
			<content:encoded><![CDATA[<p>The Single Responsibility Principle states that a class should only have one reason to change. Another possible title for this design principle would be the Single Reason to Change Principle.</p>
<p>Why is it important for a class to have a single reason to change and what are its benefits? One of the easiest ways to enhance the maintainability of a code base is to have it loosely coupled. In loosely coupled code, a change to one feature does not affect any other functionality. It is the opposite of spaghetti code where everything happens in one big method and changing how one functionality works very likely affects all the other functionality. And to get this loosely coupled code, each feature should be broken up into individual classes. If each class implements only one feature, then it only has one reason to change and when you change that feature you don’t have to worry about it breaking anything else in the code base.</p>
<p>A good example of a violation of the Single Responsibility Principle is having data validation and storage in the same class. Take a look at the code below as an example.</p>
<pre class="prettyprint">public virtual void Save(User user)
{
  if (string.IsNullOrEmpty(user.Name))
    throw new ValidationException("User name cannot be blank");

  using (var conn = new SqlConnection("connection string"))
  using (var command = conn.CreateCommand())
  {
    command.CommandText = "INSERT INTO USERS (Name) VALUES (:name)";
    command.Parameters.Add(new SqlParameter(":name", user.Name));
    command.ExecuteNonQuery();
  }
}</pre>
<p>This code violates the Single Responsibility Principle because it performs two tasks: validating the object and persisting the object. These two responsibilities are orthogonal to each other and should be separated out to two classes since neither one affects the other.</p>
<p>Now that I have explained this design pattern, I want to give my opinion on its usage. I believe this principle is good to follow when designing applications but I don’t think it should followed to a T. I say this because I see some people take it too far. For instance, take for example the interface below.</p>
<pre class="prettyprint">public interface Modem
{
  public void Dial(string phoneNumber);
  public void Hangup();
  public void Send(string message);
  public string Receive();
}</pre>
<p>Some would say the methods on this interface need separated out into 2 interfaces, one that takes care of the connection (Dial and Hangup) and another that takes care of the communication (Send and Receive). Personally I disagree. Yes, I can see how some could consider there being 2 responsibilities in this class, but then what is to keep the interface from being broken up into 4 interfaces, one for each method, because I could also see how Dial is a distinct responsibility from Hangup and Send is a different responsibility than Receive.</p>
<p>As far as implementing the Single Responsibility Principle, I personally advocate that there needs to be a sliding scale on how fine tuned the responsibilities are split out. </p>
<p>Before I expound on my position further, I need to introduce a term called responsibility group. A responsibility group is a set of responsibilities that correlate to each other in one way or another. The size of a responsibility group can be anywhere from large to small. The smaller the responsibility group, the more closely each responsibility correlates to each other, and the larger the group, the more loosely the responsibilities correlate to each other.</p>
<p>The smaller the application, the larger the responsibility group should be, and the larger the application, the smaller the responsibility group should be. The graph below shows a visual representation of what I’m talking about.</p>
<p><a href="http://blog.yodersolutions.com/wp-content/uploads/2009/12/clip-image0024.gif" ><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ApplicationResponsibility" border="0" alt="ApplicationResponsibility" src="http://blog.yodersolutions.com/wp-content/uploads/2009/12/applicationresponsibility.png" width="640" height="387" /> </a></p>
<p>I advocate this view as a result of my own experience. I volunteer my time at a non-profit organization where I have developed quite a few applications to help automate some of their administrative tasks. Many of these applications are quite small with less than 100 lines of written code. In these applications do I separate out the validation logic from the persistent logic? No, it’s not worth it. If I did I would very likely have more classes than I did lines of code. However, in my open source project (Linq to Excel) I have much smaller responsibility groups since it’s a larger project with many features.</p>
<p>One of the arguments for using this principle is making the code easier to maintain and add enhancements. But with small applications that serve a single specific purpose, it’s quite unlikely that they will change. And even if they do change and enhancements are added, the Single Responsibility Principle with smaller responsibility groups can be implemented by refactoring the code when the enhancements are added.</p>
<p>These are my thoughts and 2 cents worth on the Single Responsibility Principle. I know I do not follow the main stream of thought for this principle so I would love to receive feedback on my ideas on this principle. What is your experience with using this principle?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yodersolutions.com/2009/12/the-single-responsibility-principle/feed/</wfw:commentRss>
		</item>
		<item>
		<title>My First Encounter with jQuery</title>
		<link>http://blog.yodersolutions.com/2009/12/my-first-encounter-with-jquery/</link>
		<comments>http://blog.yodersolutions.com/2009/12/my-first-encounter-with-jquery/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 20:41:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.yodersolutions.com/2009/12/my-first-encounter-with-jquery/</guid>
		<description><![CDATA[Last week was the first time I used the jQuery javascript library and I must say I’m impressed. It has one of the simplest APIs that I have used which made learning how to use it quick and easy. In fact, I was able to write a custom plugin for it within a couple hours!
I [...]]]></description>
			<content:encoded><![CDATA[<p>Last week was the first time I used the <a href="http://jquery.com/" onclick="javascript:pageTracker._trackPageview('outbound/articles/jquery.com');" target="_blank">jQuery</a> javascript library and I must say I’m impressed. It has one of the simplest APIs that I have used which made learning how to use it quick and easy. In fact, I was able to write a custom plugin for it within a couple hours!</p>
<p>I would like to cover the business problem I had and how I used jQuery to solve it. One of the internal web sites at my company has a user rights management page where an administrator can control the individual rights on the site for each user. This page has a drop down list of all the employees which is used to give rights to a specific employee. The problem was the drop down list was not alphabetized and it contained over 1,400 employee names to choose from! It felt like finding a needle in a haystack every time a new employee was given rights.</p>
<p>The root cause of the issue was the use of a hacked together database view that returned the list of employees ordered by their full name. Database views are not supposed to have order by commands, but this one did and the website was expecting the view to provide the ordering. However, the view was not returning the employees as properly ordered. After some research it was found that the database optimizer figured that bypassing the view and using the data directly from the table was more efficient than going through the view, which meant that any code using the view would receive an unordered list of employees.</p>
<p>Once that was figured out I was able to add an order by to the sql command and the drop down list was now ordered correctly.</p>
<p>However, there is an acronym we often use at work as our motto: MISL (pronounced missile) </p>
<blockquote><p><font size="3"><font face="Courier New"><strong>M</strong>ake         <br /><strong>I</strong>t         <br /><strong>S</strong>uck         <br /><strong>L</strong>ess</font></font> </p></blockquote>
<p>And only alphabetizing the list did not Make It Suck Less enough for me. It was still a pain the neck to scroll through the 1400 employee names in the drop down list. </p>
<p>My solution was to use jQuery to replace the drop down list with an auto complete text box that had the same value as the drop down list.</p>
<p>After finding an <a href="http://docs.jquery.com/Plugins/Autocomplete" onclick="javascript:pageTracker._trackPageview('outbound/articles/docs.jquery.com');" target="_blank">auto complete plugin</a> for jQuery I was ready to implement my solution.</p>
<p>The first thing I did was hide the drop down list and add an input text box after it</p>
</p>
<pre>$dropDown = $(&quot;#EmployeeDropDownList&quot;);
$dropDown.hide()
   .after(&quot;&lt;input type='text' /&gt;&quot;);
var $autoCompleteTextBox = $dropDown.next();</pre>
<p>I then retrieve the array of employee names from the drop down list and pass it as an argument to the autocomplete plugin</p>
<pre class="prettyprint">var dropDownItems = [];
$dropDown.find("option").each(function() {
   dropDownItems.push($(this).text());
});

$autoCompleteTextBox.autocomplete(dropDownItems);</pre>
<p>I then subscribe to the blur event on the new auto complete text box to synchronize the selected value on the hidden drop down list with the value in the auto complete text box</p>
<pre class="prettyprint">$autoCompleteTextBox.blur(function() {
   var textBoxValue = $autoCompleteTextBox.val();
   $dropDown.val(textBoxValue).attr("selected", "selected");
});</pre>
<p>And finally I validate the value in the text box is the selected value in the drop down list when the submit button is clicked. </p>
<pre class="prettyprint">$("#SubmitButton").click(function(e) {
   var textBoxValue = $autoCompleteTextBox.val();
   var selectedValue = $dropDown.find("option:selected").text();
   if (textBoxValue != selectedValue)
   {
      alert(textBoxValue + " is an invalid selection");
      e.preventDefault();
   }
});</pre>
<p>I am still pretty amazed by how simple and succinct jQuery is. It was actually really fun to learn and play around with and I look forward to using jQuery in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yodersolutions.com/2009/12/my-first-encounter-with-jquery/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Learning by teaching</title>
		<link>http://blog.yodersolutions.com/2009/11/learning-by-teaching/</link>
		<comments>http://blog.yodersolutions.com/2009/11/learning-by-teaching/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 20:10:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.yodersolutions.com/2009/11/learning-by-teaching/</guid>
		<description><![CDATA[It’s been over 3 years now that I have been out of college and have done any intense studying. And by intense studying I mean studying a subject to a point that I intimately understand it and could teach it. As a software developer I am constantly reading development blogs and magazines and learning new [...]]]></description>
			<content:encoded><![CDATA[<p>It’s been over 3 years now that I have been out of college and have done any intense studying. And by intense studying I mean studying a subject to a point that I intimately understand it and could teach it. As a software developer I am constantly reading development blogs and magazines and learning new ideas and techniques, but I rarely study a new feature or enhancement to the point that I understand it. I more so study to the point that I know how to use the new feature but I don’t understand the inner workings of the feature. Take for example dynamic objects in the .Net framework 4.0. I’ve read a couple blog articles and listened to a recorded talk from PDC and now know how to implement a basic dynamic classes. I know that the new DLR allows for the use of dynamic objects but other than that I don’t know much more about dynamic objects. How much slower are they than static objects? How do you cache methods in dynamic classes? </p>
<p>I am seeing things from a birds eye view but I want to start seeing things up close and truly understand subjects I am studying. It’s often been said that the best way to learn something is to teach it. And one way to teach is to write blog posts, so I am going to write blog posts on the subjects that I am currently studying to help me more fully understand.</p>
<p>So what subject am I going to start studying? Software design principles. It’s something not taught in school and yet is what separates the good coders from the bad. </p>
<p>Here’s to studying to learn…</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yodersolutions.com/2009/11/learning-by-teaching/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How good is a Duct Tape Programmer</title>
		<link>http://blog.yodersolutions.com/2009/09/how-good-is-a-duct-tape-programmer/</link>
		<comments>http://blog.yodersolutions.com/2009/09/how-good-is-a-duct-tape-programmer/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 21:54:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.yodersolutions.com/?p=126</guid>
		<description><![CDATA[Joel Spolsky recently published a post entitled The Duct Tape Programmer. I must say that there are some points Joel makes that I strongly disagree with. I hate the attitude that getting the application done as quickly as possible is all that matters. The only situation where I would even remotely consider this is for [...]]]></description>
			<content:encoded><![CDATA[<p>Joel Spolsky recently published <a href="http://www.joelonsoftware.com/items/2009/09/23.html" onclick="javascript:pageTracker._trackPageview('outbound/articles/www.joelonsoftware.com');" target="_blank">a post entitled The Duct Tape Programmer</a>. I must say that there are some points Joel makes that I strongly disagree with. I hate the attitude that getting the application done as quickly as possible is all that matters. The only situation where I would even remotely consider this is for an app that will only be used once. Why? because an app that is used once doesn&#8217;t need to be maintained, and duct tape code that is written to ship the software as quickly as possible is horrible to maintain. So sure, you might be able to ship the app quicker and produce some extra revenue because of it, but you will lose revenue in the long run as the maintenance cost will skyrocket because it will be hard to maintain and if any enhancements are added then most likely  large amounts of code will need to be rewritten.</p>
<p>Another sentence from the post that irritates me is the following: &#8220;One principle duct tape programmers understand well is that any kind of coding technique that’s even <em>slightly</em> complicated is going to doom your project.&#8221; Really? So we should all code like we did in college and never get better? There&#8217;s a reason for the complication in some code&#8230; it&#8217;s because it makes it easier. Easier to maintain and easier to add enhancements. So what if it&#8217;s complicated. Learn it. I&#8217;m not going to write simple software just so the average joe can understand it. I&#8217;m going to write software that&#8217;s easy to maintain and easy to add enhancements, and that often means the code can become somewhat complicated.</p>
<p>Now that I went on my rant, I do think there is some good in Joel&#8217;s post. I think some programmers, myself included, like creating huge frameworks that will clean the dishes and do the laundry, but often times it is overkill and not needed. But that should not be an excuse to write half-ass code either.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yodersolutions.com/2009/09/how-good-is-a-duct-tape-programmer/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Exposing the XML Mappings in Fluent NHibernate</title>
		<link>http://blog.yodersolutions.com/2009/07/exposing-the-xml-mappings-in-fluent-nhibernate/</link>
		<comments>http://blog.yodersolutions.com/2009/07/exposing-the-xml-mappings-in-fluent-nhibernate/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 18:58:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.yodersolutions.com/2009/07/exposing-the-xml-mappings-in-fluent-nhibernate/</guid>
		<description><![CDATA[This past weekend as I was working with Fluent NHibernate, I received an error from NHibernate saying the mapping was incorrect. Since Fluent NHibernate creates the xml mappings, there wasn’t an easy way for me to see what was wrong in the xml mapping. After a little research I figured out how to get Fluent [...]]]></description>
			<content:encoded><![CDATA[<p>This past weekend as I was working with <a href="http://fluentnhibernate.org/" onclick="javascript:pageTracker._trackPageview('outbound/articles/fluentnhibernate.org');" target="_blank">Fluent NHibernate</a>, I received an error from NHibernate saying the mapping was incorrect. Since Fluent NHibernate creates the xml mappings, there wasn’t an easy way for me to see what was wrong in the xml mapping. After a little research I figured out how to get Fluent NHibernate to write the xml mappings to a directory. Check out the code below</p>
<pre class="prettyprint">var mappings = AutoPersistenceModel.MapEntitiesFromAssemblyOf<Entity>();
mappings.CompileMappings();
mappings.WriteMappingsTo("SomeDirectory");</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.yodersolutions.com/2009/07/exposing-the-xml-mappings-in-fluent-nhibernate/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Most common software development mistake</title>
		<link>http://blog.yodersolutions.com/2009/05/most-common-software-development-mistake/</link>
		<comments>http://blog.yodersolutions.com/2009/05/most-common-software-development-mistake/#comments</comments>
		<pubDate>Fri, 08 May 2009 16:08:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.yodersolutions.com/?p=120</guid>
		<description><![CDATA[Construx recently wrote a white paper about software development&#8217;s most common mistakes. These mistakes are often called classic mistakes because they happen so frequently and have such predictable results. You can read the full white paper here (you&#8217;ll have to register to download it).
Of all the classic mistakes, the most frequent one is having an [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.construx.com/" onclick="javascript:pageTracker._trackPageview('outbound/articles/www.construx.com');" target="_blank">Construx</a> recently wrote a white paper about software development&#8217;s most common mistakes. These mistakes are often called classic mistakes because they happen so frequently and have such predictable results. You can <a href="https://www.techwebonlineevents.com/ars/eventregistration.do?mode=eventreg&amp;F=1001599&amp;K=1MN1LDB" onclick="javascript:pageTracker._trackPageview('outbound/articles/www.techwebonlineevents.com');" target="_blank">read the full white paper here</a> (you&#8217;ll have to register to download it).</p>
<p>Of all the classic mistakes, the most frequent one is having an overly optimistic schedule where not enough time is given to complete a project. As I reflected on this it didn&#8217;t take me long to realize that it is also one of my personal classic mistakes.</p>
<p>In my first job I didn&#8217;t have much control of this mistake. Upper management personnel were the ones that set the deadlines for projects, and although my teammates and I regularly fought back and said we needed more time, the deadline was rarely extended. We were always able to meet the deadline, but many times we spent the next two to four weeks working out the bugs that were missed, and it didn&#8217;t make a good impression on our clients.</p>
<p>Currently I&#8217;m working at a place where I&#8217;m the only software developer, and although I am now the one that sets the schedule, I find that I also have the tendency to be overly optimistic on the deadlines, and I don&#8217;t have anyone to blame but myself. So I got to thinking why I have the tendency to be overly optimistic on project deadlines.</p>
<p>One of the causes I&#8217;m most prone to use is thinking in terms of how long it will take to create a working prototype of the application instead of creating production ready code with test coverage and clean, organized code. Many times I can get an application up and running within a day or two, but it doesn&#8217;t have any unit tests and the code is sloppy. It can take another week or two to clean up the code and write unit tests to get it production ready.</p>
<p>Another reason I find myself making overly optimistic schedules is because I base the schedule out of being able to work on it full time. However, I&#8217;m never fully able to actually work on the project full time because I get pulled into other projects and tasks.</p>
<p>I love playing with new tools and libraries, but I find that they are also another cause for this classic mistake. Tools usually save time on a project, but the learning curve when first learning a tool can drastically add time to the project, and I often times forget to factor in the learning curve time when deciding on deadlines. /For example, NHibernate has been a great tool I use and saves a ton of time, but the learning curve is large and it took me quite some time before I was up to speed with it.</p>
<p>I often like to think that I&#8217;m too good a software developer to fall into making classic mistakes, but it is evident that I&#8217;m not much different from others and have the same tendencies. But now that I know this mistake is one of my weak spots, hopefully I can be mindful of it in the future and not fall into making the same classic mistake.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yodersolutions.com/2009/05/most-common-software-development-mistake/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Some Good Inspiration</title>
		<link>http://blog.yodersolutions.com/2009/03/some-good-inspiration/</link>
		<comments>http://blog.yodersolutions.com/2009/03/some-good-inspiration/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 22:08:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.yodersolutions.com/net/?p=118</guid>
		<description><![CDATA[I resonated with the following article by JP Boodhoo: http://blog.jpboodhoo.com/FocusOnFunAndStepIntoFreedomInYourCareer.aspx
I must admit I have lost the &#8220;fun&#8221; in programming lately and desire to get it back. One thing I&#8217;ve always wanted to do was be part of an open source project but I&#8217;ve been too timid to do so. I&#8217;ve also been overwhelmed by all [...]]]></description>
			<content:encoded><![CDATA[<p>I resonated with the following article by JP Boodhoo: <a href="http://blog.jpboodhoo.com/FocusOnFunAndStepIntoFreedomInYourCareer.aspx" onclick="javascript:pageTracker._trackPageview('outbound/articles/blog.jpboodhoo.com');" target="_blank">http://blog.jpboodhoo.com/FocusOnFunAndStepIntoFreedomInYourCareer.aspx</a></p>
<p>I must admit I have lost the &#8220;fun&#8221; in programming lately and desire to get it back. One thing I&#8217;ve always wanted to do was be part of an open source project but I&#8217;ve been too timid to do so. I&#8217;ve also been overwhelmed by all the open source projects and not knowing which one I should commit to. So this past weekend I committed to working on the <a href="http://fluentnhibernate.org/" onclick="javascript:pageTracker._trackPageview('outbound/articles/fluentnhibernate.org');" target="_blank">Fluent NHibernate</a> project. This project allows you to make NHibernate mappings in the code, where it is compile-safe and has refactoring ability, instead of using the hbm xml files. I&#8217;ve used it in a couple of my projects and its fluent interface is very welcomed over the xml files.</p>
<p>So here&#8217;s to having fun programming once again.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yodersolutions.com/2009/03/some-good-inspiration/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Methods in ExpressionTrees/Linq Statements</title>
		<link>http://blog.yodersolutions.com/2008/12/using-methods-in-expressiontreeslinq-statements/</link>
		<comments>http://blog.yodersolutions.com/2008/12/using-methods-in-expressiontreeslinq-statements/#comments</comments>
		<pubDate>Fri, 26 Dec 2008 18:43:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Linq]]></category>

		<category><![CDATA[LinqToExcel]]></category>

		<guid isPermaLink="false">http://blogs.yodersolutions.com/net/2008/12/26/using-methods-in-expressiontreeslinq-statements/</guid>
		<description><![CDATA[I&#8217;ve been working on my LinqToExcel open source project over this Christmas vacation, and currently I am trying to allow method calls to be used in the Linq statement like the example below shows
private int GetLargeEmployeeCount()
{
  return 200;
}

public Company[] GetLargeCompanies()
{
  IExcelRepository repo = new ExcelRepository("companies.xls");
  var companies = from c in repo.WorkSheet()
 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on my <a href="http://code.google.com/p/linqtoexcel/" onclick="javascript:pageTracker._trackPageview('outbound/articles/code.google.com');" target="_blank">LinqToExcel</a> open source project over this Christmas vacation, and currently I am trying to allow method calls to be used in the Linq statement like the example below shows</p>
<pre class="prettyprint">private int GetLargeEmployeeCount()
{
  return 200;
}

public Company[] GetLargeCompanies()
{
  IExcelRepository repo = new ExcelRepository("companies.xls");
  var companies = from c in repo.WorkSheet()
                  where c.EmployeeCount >= GetLargeEmployeeCount()
                  select c;

  return companies.ToArray();
}</pre>
<p>Let&#8217;s take a quick look at the created ExpressionTree.</p>
<p><a href="http://blogs.yodersolutions.com/net/wp-content/uploads/2008/12/expression_tree.jpg" ><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" src="http://blogs.yodersolutions.com/net/wp-content/uploads/2008/12/expression_tree.jpg" border="0" alt="expression_tree" width="450" height="752" /></a></p>
<p>Now let&#8217;s look at the method that handles getting the value from the <em>GetLargeEmployeeCount()</em> method. The <a href="http://linqtoexcel.googlecode.com/svn/trunk/src/LinqToExcel/SQLExpressionVisitor.cs" onclick="javascript:pageTracker._trackPageview('outbound/articles/linqtoexcel.googlecode.com');" target="_blank">SQLExpressionVisitor</a> class is responsible for converting the ExpressionTree created from the Linq statement into the SQL statement that will be used. <a href="http://linqtoexcel.googlecode.com/svn/trunk/src/LinqToExcel/SQLExpressionVisitor.cs" onclick="javascript:pageTracker._trackPageview('outbound/articles/linqtoexcel.googlecode.com');" target="_blank">SQLExpressionVisitor</a> inherits from the common <a href="http://linqtoexcel.googlecode.com/svn/trunk/src/LinqToExcel/ExpressionVisitor.cs" onclick="javascript:pageTracker._trackPageview('outbound/articles/linqtoexcel.googlecode.com');" target="_blank">ExpressionVisitor</a> class to aid in walking through the ExpressionTree.</p>
<p>The pertinent node that deals with the <em>GetLargeEmployeeCount()</em> method is highlighted in blue above. The return value from <em>GetLargeEmployeeCount()</em> is retrieved in <em>VisitMethodCall()</em>.</p>
<pre class="prettyprint">protected override Expression VisitMethodCall(MethodCallExpression m)
{
  if (m.Method.Name == "Where")
  {
    _sql.Append(" WHERE ");
    this.Visit(m.Arguments[1]);
  }
  else if (m.Method.Name != "Select")
  {
    object methodObject = ((ConstantExpression)m.Object).Value;
    object methodValue = m.Method.Invoke(methodObject, GetMethodArguments(m.Arguments));
    _params.Add(new OleDbParameter("?", methodValue));
    _sql.Append("?");
  }
  return m;
}</pre>
<p><em>VisitMethodCall()</em> is responsible for dealing with ExpressionTree nodes that contain method calls. It turns out that the <em>where</em> in a Linq statement is actually a method call, so we append a &#8220;WHERE&#8221; to the string sql statement. _<em>sql</em> is a private StringBuilder object that is used to construct the sql statement based on the ExpressionTree.</p>
<p>But the code we&#8217;re really interested in is contained in the <em>else if</em> code block. The <em>select</em> Linq statement is also a method call and we&#8217;re not interested in that, so we ignore it in the <em>else if</em> condition.</p>
<p>Now we&#8217;re interested in getting the return value of the method. Let&#8217;s take another closer look at the Expression node for the <em>GetLargeEmployeeCount()</em> method.</p>
<p><a href="http://blogs.yodersolutions.com/net/wp-content/uploads/2008/12/method_expression.jpg" ><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" src="http://blogs.yodersolutions.com/net/wp-content/uploads/2008/12/method_expression.jpg" border="0" alt="method_expression" width="418" height="202" /></a></p>
<p>This node contains all the information we need to use reflection to get the method return value. The first thing we need to do is get the object that contains the method, which we can get from the m.Object property with some casting of types.</p>
<pre class="prettyprint">object methodObject = ((ConstantExpression)m.Object).Value;</pre>
<p>Now that we have the method object, we can use reflection to invoke the method and get the return value. I first tried to use type reflection to invoke the method.</p>
<pre class="prettyprint">object returnValue = methodObject.GetType().InvokeMember(m.Method.Name, BindingFlags.InvokeMethod, null, methodObject, GetMethodArguments(m.Arguments));</pre>
<p>However, this only works when the method is public. If it isn&#8217;t then a <em>MissingMethodException</em> is thrown. Of course, only being able to use public methods is not acceptable, so we need to use <em>Invoke()</em> on the MethodInfo object to invoke the method.</p>
<pre class="prettyprint">object returnValue = m.Method.Invoke(methodObject, GetMethodArguments(m.Arguments));</pre>
<p>The rest of the code block (_<em>params</em> and _<em>sql</em>) deals with generating the sql from the ExpressionTree.</p>
<p>One last point of interest is the <em>GetMethodArguments()</em>. This is a helper method that takes ReadOnlyCollection&lt;Expression&gt; and returns an array of corresponding objects. You can check it out in the <a href="http://linqtoexcel.googlecode.com/svn/trunk/src/LinqToExcel/SQLExpressionVisitor.cs" onclick="javascript:pageTracker._trackPageview('outbound/articles/linqtoexcel.googlecode.com');" target="_blank">SQLExpressionVisitor</a> class if you&#8217;re interested in its implementation.</p>
<p>It turns out that it only takes a couple lines of code to get the return value for a method used in a Linq statement, but I spent a couple hours researching how to do it, so hopefully this article will be of help to others who are creating custom Linq providers.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yodersolutions.com/2008/12/using-methods-in-expressiontreeslinq-statements/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Getting MS Access to work with NHibernate</title>
		<link>http://blog.yodersolutions.com/2008/12/getting-ms-access-to-work-with-nhibernate/</link>
		<comments>http://blog.yodersolutions.com/2008/12/getting-ms-access-to-work-with-nhibernate/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 19:27:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://blogs.yodersolutions.com/net/2008/12/18/getting-ms-access-to-work-with-nhibernate/</guid>
		<description><![CDATA[I am continuing to play with NHibernate and wanted to use MS Access as the database back end. I thought it would be an easy migration that required only a couple NHibernate configuration settings being changed below.
&#60;property name="dialect"&#62;
  NHibernate.JetDriver.JetDialect, NHibernate.JetDriver
&#60;/property&#62;
&#60;property name="connection.driver_class"&#62;
  NHibernate.JetDriver.JetDriver, NHibernate.JetDriver
&#60;/property&#62;
&#60;property name="connection.connection_string"&#62;
  Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb
&#60;/property&#62;
But when I started up NHibernate, I [...]]]></description>
			<content:encoded><![CDATA[<p>I am continuing to play with NHibernate and wanted to use MS Access as the database back end. I thought it would be an easy migration that required only a couple NHibernate configuration settings being changed below.</p>
<pre style="border-right: gray 1px solid; border-top: gray 1px solid; border-left: gray 1px solid; border-bottom: gray 1px solid">&lt;property name="dialect"&gt;
  NHibernate.JetDriver.JetDialect, NHibernate.JetDriver
&lt;/property&gt;
&lt;property name="connection.driver_class"&gt;
  NHibernate.JetDriver.JetDriver, NHibernate.JetDriver
&lt;/property&gt;
&lt;property name="connection.connection_string"&gt;
  Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb
&lt;/property&gt;</pre>
<p>But when I started up NHibernate, I received the following error:</p>
<blockquote><p>System.IO.FileNotFoundException: Could not load file or assembly &#8216;NHibernate.JetDriver&#8217; or one of its dependencies. The system cannot find the file specified.</p>
<p>File name: &#8216;NHibernate.JetDriver&#8217;</p></blockquote>
<p>It turns out I needed to add the NHibernate.JetDriver DLL to the project. This DLL is not part of the main NHibernate project. It is located in the <a href="http://sourceforge.net/projects/nhcontrib/" onclick="javascript:pageTracker._trackPageview('outbound/articles/sourceforge.net');" target="_blank">NHibernate Contrib project</a> on Source Forge.</p>
<h3>Building the NHibernate.JetDriver</h3>
<ol>
<li>Checkout the source code from Source Forge
<ol>
<li>url: <a title="https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk" href="https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk" onclick="javascript:pageTracker._trackPageview('outbound/articles/nhcontrib.svn.sourceforge.net');">https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk</a></li>
</ol>
</li>
<li>Build the NHibernate.JetDriver project
<ol>
<li>Directory Location from trunk: /trunk/src/NHibernate.JetDriver</li>
<li>The easiest way to build it is using the NAnt script included in the project (default.build)
<ol>
<li>the NAnt script creates a &#8220;build&#8221; folder and places the driver in there</li>
</ol>
</li>
<li>You can also open the project and build it from there
<ol>
<li>The driver will be located in: NHibernate.JetDriver\bin\Debug</li>
</ol>
</li>
</ol>
</li>
</ol>
<p>Once you create the NHibernate.JetDriver all you need to do it copy it to your project directory and reference it from your project and then you should be good to use MS Access with NHibernate.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yodersolutions.com/2008/12/getting-ms-access-to-work-with-nhibernate/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Typealyzer</title>
		<link>http://blog.yodersolutions.com/2008/12/typealyzer/</link>
		<comments>http://blog.yodersolutions.com/2008/12/typealyzer/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 15:20:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.yodersolutions.com/net/?p=91</guid>
		<description><![CDATA[Oren Eini posted his results from typealyzer which determines your personality profile by reading your blog. So I thought I would see what the typealyzer said about me based upon my blog.
INTJ - The Scientists
The long-range thinking and individualistic type. They are especially good at looking at almost anything and figuring out a way of [...]]]></description>
			<content:encoded><![CDATA[<p>Oren Eini <a href="http://ayende.com/Blog/archive/2008/12/01/the-typealyzer.aspx" onclick="javascript:pageTracker._trackPageview('outbound/articles/ayende.com');" target="_blank">posted</a> his results from <a href="http://www.typealyzer.com/" onclick="javascript:pageTracker._trackPageview('outbound/articles/www.typealyzer.com');" target="_blank">typealyzer</a> which determines your personality profile by reading your blog. So I thought I would see what the typealyzer said about me based upon my blog.</p>
<h2>INTJ - The Scientists</h2>
<p style="padding-left: 30px;">The long-range thinking and individualistic type. They are especially good at looking at almost anything and figuring out a way of improving it - often with a highly creative and imaginative touch. They are intellectually curious and daring, but might be pshysically hesitant to try new things.</p>
<p style="padding-left: 30px;">The Scientists enjoy theoretical work that allows them to use their strong minds and bold creativity. Since they tend to be so abstract and theoretical in their communication they often have a problem communcating their visions to other people and need to learn patience and use conrete examples. Since they are extremly good at concentrating they often have no trouble working alone.</p>
<p>I would have to say that description fits me pretty well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yodersolutions.com/2008/12/typealyzer/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
