Tuesday, December 16, 2008

If you are coming out to the Philly.Net meeting on Wednesday, don't forget to bring some cans of food or other non-perishables.  We are collecting food to donate to a local food bank.  Steve Andrews will have the exact details tomorrow night.  All year round many people in our area are hungry.  Let's try to make a difference tomorrow night by collecting a lot of food to help.  Those of us in the Philly.Net leadership have wanted to be more charitable for a while now, it is nice that Steve got this idea going.  Check out GeekFoodDrive for more details on the program.

If you have any other similar ideas and want to get involved, just let us know.

Tuesday, December 16, 2008 7:48:51 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, December 01, 2008

I used to be Andy the Employee, but now I am Andy the Contractor.  Ok, enough election puns.  Actually I would write more but I can't think of any right now.

After many years of working as an employee, I have decided to become and Independent Contractor/Consultant.  What does that mean?  Well really it isn't all that different.  From day to day, my job will still be the same but now I have to make sure I can find enough work to keep myself busy.  So I guess my job will be harder.  Plus I get no health benefits and I have to pay more taxes out of my paycheck.  Hey, this isn't sounding too great!  Actually, a lot of software developers work this way and they seem to like it.  There are pros to this work model too.  You typically get paid more to cover the extra taxes, etc.  I hope that turns out to be the case.  And you get to choose the kind of projects you want to take on which is great.  I have worked for several consulting companies over the years and I didn't always like the assignments I got, well now I am in control!

Now I have a lot of work to do and I hope to blog about the process.  I need to set up a company (incorporate), figure out how to track expenses and billing, and finish a list of other business management stuff.  I've been talking to a lot of people about the benefits of different business structures:  DBA (Doing Business As), LLC (Limited Liability Company), and S-Corp.  It seems that they each have different tax benefits in the order I listed them.  S-Corp has, from what I can tell, the best tax breaks but seems to be the hardest to manage.  I think most software developer types choose LLC because of the benefits/complications ration is pretty good.  I need to figure it all out.

Also, I plan on learning some new technology and hopefully some good blog posts will come of it.  In the meantime, here goes nothing...

Monday, December 01, 2008 10:20:02 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [2]  |  Trackback

We just got back from our family trip to see family in Phoenix, AZ.  Our annual Thanksgiving trip west includes us three plus my in-laws, Rebecca's sister, her husband and their 3 kids heading out to visit family in Arizona.  We had a great time, it is too bad we only see Rebecca's Grandmom, Aunt, Uncle and Cousin once in a while.  Ben loved the trip...he got a lot of attention which always makes him happy.  I wouldn't exactly say he loved the plane ride but he behaved pretty well, all things considered. 

Thank you TSA: OK, I can't believe I am going to do this, but I feel the need to compliment the TSA (Transportation Safety Administration) for a job well done over the holiday weekend.  What?  Yes, it is true.  When we departed from Philly, we were shocked to find out that they had implemented a family line!  The regular line wasn't too bad but probably a 10-15 minute wait. But much to our surprise, we got to use the family line (thanks Ben!) and we moved right to the front.  Once into the screening area we found the staff to be friendly, courteous and very helpful.  Some of the TSA employees even helped us with all of our stuff!  I don't recall it being like that last time, or ever.  Was it always staffed by TSA, or was it a private company before?  I don't know what has changed but I say "Keep up the good work".  Us bloggers are quick to complain on the web about things we don't like, so we should also point out when things work well!  We found a similar situation in Phoenix on the return trip.

BOOOO US Air:  Speaking of complaining, it is time to do so.  US Air (and Airlines in general) have really gotten ridiculous.  OK, I get charging me for my luggage and even for a drink.  I don't like it, but I get it.  But where is my movie?  We went on a five hour cross country flight and they couldn't show a movie?  How about a few TV re-runs?  What about some kind of travel programming?  Even an infomercial would have entertained me!  How much does it cost to run that in flight entertainment?  There are commercials on it, so it can't cost too much.  Don't they know that if I had a movie it would have taken my mind off the fact that the flight stinks - the seats are too close together, the temperature is either too hot or too cold, they charge me for my meal, they charge me for a drink, they charge me for my luggage.  What's next, a charge to use the bathroom?  OK, moving on...

Travel Tips:  Ben is 9.5 months old and isn't the kind of kid who can sleep on someone's lap.  So we got him a seat on the plane.  It is expensive but worth it.  So we brought his car seat on with us for him to sleep in.  It worked out pretty well.  The doctors say Benadryl is a no-no for kids his age.  Too bad, because it would have helped him relax.  Instead they recommend a dose of infant Tylenol prior to boarding the plane.  Ben is teething too, so that seemed like a good idea.  Remember that baby's can't clear the pressure from their ears like we do when the pressure of taking off or landing builds.  They recommend a bottle or nursing to help.  Timing is the key though.  It isn't the actual landing or take off, it is the time when the planes altitude changes the most that counts.  That's a big deal for a kid like Ben, who nurses pretty quickly.  If we time it wrong, he'll finish and won't be too happy with the pressure change.  Luckily that went ok.  During the flight he mostly slept.  We put the "hood" up on the car seat and covered more of the opening with a shirt, so it would be nice and dark for him.  By the way, the evening flight was much easier than the day time flight because the little ones expect to sleep more.  By the way, the last time we flew Ben was only about 3.5 months old.  That time, he slept great because we used the Baby Bjorn to keep him snuggled up with us for the whole flight.  We didn't bother to get him his own seat because he was really little.  He was so happy on that flight lying on us!

Oh yeah, Arizona:  As I said, Ben loved the trip.  He got to sleep in a hotel, eat in a lot of restaurants, see Great Grandma, play in her house, sit by the pool, stay up late, and play with the whole family.  One night he got to go play with his Bubbie and Zeyda (Grandma and Grandpa) while we went out to dinner.  That was great!  The weather in AZ was not too great (cool and rainy) and over a few days there, we spent about 2 hours total at the pool.

I know, you just want to see Pictures of Ben.  Here you go: (Don't forget, you can click the photos to see a bigger version)

DSC03815 DSC03840 DSC03844 DSC03848 DSC03781 DSC03856 DSC03853 DSC03851 DSC03862

 |  | 
Monday, December 01, 2008 9:42:43 AM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, November 24, 2008

Tonight at Philly.Net we are having our annual "15 Minutes of Fame" meeting.  That is where we have 10 of our regular presenters do a short 15 minute presentation on something they think is cool.  We've got a great line up planned for tonight and I am excited to not just present my topic but also learn a few things.  These mini presentations give the audience just enough to get started, plant a seed, wet your whistle, etc. 

It's not always so easy to come up with an idea for such a short presentation.  I thought LINQ Compiled Queries was a good one because, while it is a big feature of LINQ, it is relatively easy to implement.  I also think people avoid it because it sounds complicated.  In fact, it is not. 

I'll demonstrate with some code taken from this VS2008 solution.

Here is a regular method that takes a few parameters, executes a "SELECT" on the Northwind Customers table, and returns a list of Orders.  You'll also note that there are parameters to support paging, a common scenario with LINQ.

public static List<Order> GetOrdersNotCompiled(string custName, string shipCountry, int skip, int take)
{
    //even though the query is compiled, you can still pass in parameters. 
    using (NorthwindDataContext db = new NorthwindDataContext())
    {
        List<Order> orders = (from order in db.Orders
                              where order.Customer.CompanyName == custName
                                    && order.ShipCountry == shipCountry
                              select order).Skip(skip).Take(take).ToList();

        return orders;
    }
}

So how to convert this to a Compiled Query?

A Compiled Queries get stored as a Static Func<>.  A Func acts as a "pointer" to a method.  We make it static so it can be reused across the application.  That is how we get the performance gain.  Once the .Net framework figures out how to take the LINQ and turn it into a SQL statement, it gets saved for reuse in the Static variable.

A Func<> has a limited number of parameters that can be passed to it.  I like the technique of standardizing what gets passed in, passing the datacontext in the first parameter and a "helper class" containing all other parameters as the second.  And of course, last is the out parameter.

Here is our helper class:

private class GetOrdersInputs
{
    public string CustomerName { get; set; }
    public string ShipCountry { get; set; }
    public int Take { get; set; }
    public int Skip { get; set; }
}

Now let's look at the Func<> declaration:

private static Func<NorthwindDataContext, GetOrdersInputs, IQueryable<Order>> GetOrdersQuery =
    CompiledQuery.Compile((NorthwindDataContext db, GetOrdersInputs inputs) => LINQ GOES HERE );

You can see that the Compile method takes a lambda expression.  I thought it was easier to follow without the complete LINQ.  Here is the complete version:

private static Func<NorthwindDataContext, GetOrdersInputs, IQueryable<Order>> GetOrdersQuery =
    CompiledQuery.Compile((NorthwindDataContext db, GetOrdersInputs inputs) =>
                          (from order in db.Orders
                           where order.Customer.CompanyName == inputs.CustomerName
                                 && order.ShipCountry == inputs.ShipCountry
                           select order).Skip(inputs.Skip).Take(inputs.Take));

Don't worry if the Func<> seems confusing.  You'll find it very easy to use over and over again, just replace the variables and the LINQ statement anytime you need it.

Now you just call GetOrdersQuery as follows:

public static List<Order> GetOrdersCompiled(string custName, string shipCountry, int skip, int take)
{

    // load up the helper class with parameters.
    GetOrdersInputs inputs = new GetOrdersInputs { CustomerName = custName, ShipCountry = shipCountry, Skip = skip, Take = take };

    // even though the query is compiled, you can still pass in parameters.
   
using (NorthwindDataContext db = new NorthwindDataContext())
    {

        // Execute the compiled query.
        List<Order> orders = GetOrdersQuery(db, inputs).ToList();
        return orders;
    }
}

Results:  The included demo is a little Console App that runs each query 27 times.  I'm using a free tool - CLR Profiler from Microsoft to analyze my application.

The compiled query executes about 257 thousand method calls (that is .net converting the LINQ into SQL).  But the non compiled version executes about 2.6 million calls because it does the work over and over again!

CLR Compiled

 

The Compiled Query will perform much better and it really wasn't much work to implement.  So give it a try!

Again, here is the source code:  CompiledQuery.zip

Technorati Tags: ,
 | 
Monday, November 24, 2008 1:17:41 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [3]  |  Trackback
 Friday, October 24, 2008

Looking at my blog I see that I haven't posted any pictures of Ben since the end of August!  Wow, time flies.  A lot has changed since then with Benny.  When we last left our hero he was learning to sit up.  Well these days he's all about being mobile.  He's  crawling all over and loves to follow us around.  The changes have been so exciting to watch.  When he first sat up on his own he was so happy because he could play by himself with toys.  Now, he can crawl around, find something to play with, move on to the next toy, crawl over here and crawl over there.  He has become quite independent and he is very proud of himself.  He has times when he really wants to be held but on the other hand he has times when he can play all by himself for a pretty long time.

Of course, we had to baby-proof the house now.  Ben loves to get into trouble too.  It seems that this kid has an instinct for grabbing anything he isn't supposed to!  In general, Ben is a fun kid but he's pretty independent and stubborn too.  I'm really surprised at how much of a personality a little 8 month old kid can have.  I wonder how much he'll change that as he gets older.  Anyway, here are some pictures of our Benny. 

 

DSC03709DSC03739 DSC03742DSC03744  DSC03745   DSC03748 Cropped DSC03762

 | 
Friday, October 24, 2008 7:29:25 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Wednesday, October 15, 2008

My contact at O'Reilly sent me this.  It's a bit last minute, but if you have time, please help them.  Maybe you'll win a free book!  Unfortunately it needs to be complete before Oct 17th.

O'Reilly Media is conducting research about in-person, live workshops on
software and business topics, and we'd really like your opinion.  If you
live in the United States and work in the tech industry, please consider
taking our 19 question survey to help us understand what you look for in
a live training course what motivates you, what you expect to get out
of a workshop, what topics you'd like to see, and so forth.  

To participate, please go to:
https://www.surveymonkey.com/s.aspx?sm=3bFGXzVnXige7WrPdJ0wAQ_3d_3d

To show our appreciation, we'll select 10 people at random to receive a
free book of your choice.  The drawing will happen on Friday, October
17, so you'll need to complete the survey by that date to enter.  The
last question on the survey will ask for your e-mail we'll use that
only to contact the randomly selected winners and your responses will
remain anonymous.

Wednesday, October 15, 2008 7:21:25 AM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, October 13, 2008

Philly.Net Code Camp was great.  We had over 400 people attend and the feedback is very good.

I had a great time with my presentation "Make the Switch to LINQ - Working with data will never be the same".  Thanks to everyone who joined me.  It was pretty crowded.  Thanks to those of you who stood up or sat on the floor.  I know that I covered a lot of information in my session.  I hope I didn't go to fast.  I promised that I'd have my Code Camp presentation up on my blog by today.  I'm running a little behind schedule.  Update:  here it is!  On schedule, even if it is 10:30 at night!

I've included a db create script, all of my source code, and the slides.  I have tried to add more comments to the code so it makes sense.  At the end I was pretty rushed and didn't explain all of the samples but I hope they speak for themselves.

If you have any questions, just ask... you can contact through the link on my blog.  I've also included my address in a ReadMe.txt doc in the zip file.

LINQ Demo.zip (900.4 KB)

Now, make the switch to LINQ!

 |  | 
Monday, October 13, 2008 5:16:55 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Tuesday, October 07, 2008

If you haven't checked out the CLR Profiler, it is a pretty cool tool.  It's free from Microsoft and it allows you to do some profiling of applications - apps, services, or asp.net sites.  It may not compete with the high end fancy profilers that are available for purchase, but you get some decent functionality for free.

I'm no expert on this product, in fact, I have only used it a few times to do a few specific things.  Last night I needed to use it on my laptop (never had it on that machine before) and I found myself struggling to get it up and running.  The weird part is that it felt strangely familiar, like I had the same problem when I used it a few months prior.  So I'm writing this post for 2 reasons.  Hopefully it will help you if you have the same problem.  And also, hopefully in a few months when I start it again, if I hit the same problem, I'll search the Internet and find this post that I am leaving for myself!

First, make sure you have the correct version of CLR Profiler.  There are two versions available.  .Net Framework 1.1 and .Net Framework 2.0.  There is no version for the .Net Framework 3.5 but don't worry, the 2.0 version will do that trick.  The two versions look the same and surprisingly, if you search for CLR Profiler, most of the links that come up are for the 1.1 version.  So here are two links:

Now here is the part that got me this time...

I kept getting this message:  "Waiting for application to start common language runtime".

image At the time, I was using Remote Desktop to my laptop.  That may have had something to do with my issue, but I'm not sure.  I re-installed CLR Profiler to make sure I hadn't installed the wrong version.  Same problem happens! 

imageBut then I had a flash of genius (ok, maybe not genius) and my problem was solved:  I right clicked the CLRProfiler.exe and used "Run as administrator".  Everything works great.  Interestingly, it works for me today without using "Run as admin".  So was it my Remote Desktop interfering?  Could be.  But the bottom line is, "Run as administrator" solved the problem.  I hope this helps you too.

Tuesday, October 07, 2008 7:13:28 AM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [5]  |  Trackback