LINQed IN

Blog by Troy Magennis on Software Architecture, Development and Management

About the author

Troy Magennis is a software developer living in Seattle, WA. Troy is a Microsoft MVP, the author of many articles, and the founder of HookedOnLINQ.com, a LINQ specific wiki reference site.
E-mail me Send mail

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Google Chart API

Old news to many, but Google has a Charting API that allows the creation of numerous chart types via a formatted URL string. The Google Chart API returns a .PNG file which is easily embedded in an image tag. If you want to embed charts into your web applications, this chart API might help get you to market quicker.

The idea is simple enough - create an API which returns an image given a specially formed URL. Values can be specified in-line, or encoded to make them more manageable. There are too many chart types and options to document here, but Google's documentation for this API is pretty extensive. I'm impressed with the approach and simplicity. I'm also impressed with the breadth of chart types and the number of options available. In general - they just look plain cool!

Although the API is pretty easy to drive natively, there is also a .NET Helper Library called ngchart which simplifies the API's from native .NET code.

 

Enough talk - some examples -

http://chart.apis.google.com/chart?cht=p3&chd=s:Uf9a&chs=250x100&chl=January|February|March|April

 

http://chart.apis.google.com/chart?cht=v&chs=200x100&chd=t:100,80,60,30,30,30,10

 

http://chart.apis.google.com/chart?chs=225x125&cht=gom&chd=t:70&chl=Hello

 

http://chart.apis.google.com/chart?cht=lxy&chs=200x125&chd=t:0,30,60,70,90,95,100|20,30,40,50,60,70,80|10,30,40,45,52|100,90,40,20,10|-1|5,33,50,55,7&chco=3072F3,ff0000,00aaaa&chls=2,4,1&chm=s,FF0000,0,-1,5|s,0000ff,1,-1,5|s,00aa00,2,-1,5

 

http://chart.apis.google.com/chart?chco=f5f5f5,edf0d4,6c9642,365e24,13390a&chd=s:fSGBDQBQBBAGABCBDAKLCDGFCLBBEBBEPASDKJBDD9BHHEAACAC&chf=bg,s,eaf7fe&chtm=usa&chld=NYPATNWVNVNJNHVAHIVTNMNCNDNELASDDCDEFLWAKSWIORKYMEOHIAIDCTWYUTINILAKTXCOMDMAALMOMNCAOKMIGAAZMTMSSCRIAR&chs=440x220&cht=t


Posted by t_magennis on Monday, August 04, 2008 3:18 PM
Permalink | Comments (1) | Post RSSRSS comment feed

Determining SQL Server Object Dependencies for a Stored Procedure or Other Database Object Name

Finding what dependencies a Stored Procedure has on underlying tables, views, functions, etc is often necessary when trying to assess the impact of a change. SQL Server has built-in functions that will indicate in most cases a dependency for any object in the database. The system view "sys.sql_dependencies" is viewed with skepticism by some people who have obviously been bitten in the past.

In order to see for myself the results, I wrote a simple helper class, and thought i'd share the boilerplate code to start you off here (I may clean it up and share it as a library, email me if you have difficulty getting it running). Its a rough prototype, but it is returning good results for my purposes.

Note: This code requires Visual Studio 2008. It uses LINQ to SQL in a very loose way due to the LINQ to SQL Designer not listing the System Views and Functions. Its a good example of just how flexible LINQ to SQL is though.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Configuration;

namespace DatabaseDependencyCrawler
{
    public class SysDependsResult
    {
        public int referenced_major_id { get; set; }
    }

    public class ObjectInfoResult
    {
        public int id { get; set; }
        public string name { get; set; }
        public string xtype  { get; set; }
        public DateTime crdate { get; set; }
    }

    public class DatabaseDependencyCrawler
    {
        public List<DatabaseDependencyEntity> GetDBObjectDependencies(string connectionString, string name)
        {
            // the system views built-into SQL Server 2005
            string dependsQuery = "select referenced_major_id from sys.sql_dependencies where object_id = object_id('{0}')";
            string objectInfoQuery = "select * from sys.sysobjects where id in ( {0} )";

            List<DatabaseDependencyEntity> result = new List<DatabaseDependencyEntity>();

            // find the list of dependencies based upon a database object's name
            DataContext context = new DataContext(connectionString);

            var dependencies = (IEnumerable<dependencies>)context.ExecuteQuery(
                typeof(SysDependsResult),
                string.Format(dependsQuery, name), 
                new object[] { });

            // build a list of object_is's to we can ask for their name in a second query
            StringBuilder ids = new StringBuilder();
            foreach (SysDependsResult d in dependencies)
            {
                if (ids.Length > 0)
                     ids.Append(",");

                ids.Append(d.referenced_major_id);
            }

            // if any records were found...lookup the names of those id's comma separated
            if (ids.Length > 0)
            {

                IEnumerable<ObjectInfoResult> objects = (IEnumerable<ObjectInfoResult>)context.ExecuteQuery(typeof(ObjectInfoResult),
                    string.Format(objectInfoQuery, ids.ToString()),
                    new object[] { });

                foreach (ObjectInfoResult o in objects)
                {
                    result.Add (
                        new DatabaseDependencyEntity {
                            DatabaseConnectionString = connectionString,
                            SourceObject = name,
                            Dependent = o
                        });
                }
            }
        
            return result;
        }
    }
}

Categories: C# | LINQ | Resources
Posted by t_magennis on Tuesday, July 15, 2008 5:34 AM
Permalink | Comments (3) | Post RSSRSS comment feed

Microsoft SharedView

Old news to many, but I had a need to share my desktop today for a conference call. I remembered Microsoft had ShareView coming out of beta, so I downloaded it and was up and running in a few minutes. Its well worth your time having installed. For demo'ing a website prototype to external people, it worked great.

Microsoft ShareView download

Microsoft ShareView Connect Page

Overview

  • Hold more effective meetings and conference calls
  • Connect with up to 15 people in different locations and get your point across by showing them what's on your screen.
  • Work together in real time
  • Share, review, and update documents with multiple people in real time.
  • Use when and where you want
  • SharedView is easy to use, from anywhere, at a moment's notice.

 

I can see this coming in useful for all sorts of ad-hoc collaboration. I'd like to know how it goes as a remote pair-programming platform as well.

Troy.


Posted by t_magennis on Wednesday, July 02, 2008 10:25 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Programming Quotes and Wisdom

I found a good set of programming, and software development quotes. Here is a short-list of my favorites I found at this site. If you know of any other good programming quote websites, leave a comment.

"The Six Phases of a Project:

  • Enthusiasm
  • Disillusionment
  • Panic
  • Search for the Guilty
  • Punishment of the Innocent
  • Praise for non-participants"

Anon

 

"Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why - Programmers combine theory and practice: Nothing works and they don't know why."

Anon

 

"Good judgement comes from experience, and experience comes from bad judgement."

Fred Brooks

 

"The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time."

Tom Cargill

 

"Learning is not compulsory. Neither is survival."

W. Edwards Deming

 

"Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "

Albert Einstein

 

"Measuring programming progress by lines of code is like measuring aircraft building progress by weight. "

Bill Gates

 

"The perfect project plan is possible if one first documents a list of all the unknowns. "

Bill Langley

 

"There are two ways to write error-free programs; only the third works. "

Alan J. Perlis

 

"Without requirements or design, programming is the art of adding bugs to an empty text file."

Louis Srygley

 

"I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone."

Bjarne Stroustrup

 

"There are only two industries that refer to their customers as "users". "

Edward Tufte

 

"We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise. "

Larry Wall

 

"As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs."

Maurice Wilkes discovers debugging, 1949


Tags:
Posted by t_magennis on Thursday, June 26, 2008 5:17 AM
Permalink | Comments (0) | Post RSSRSS comment feed

.NET 3.5 Enhancements Training Kit

A comprehensive set of hands on labs and training material has been release for a number of .NET 3.5 Enhancements by the Visual Studio & .NET Framework evangelism team. Nice work guys.

"The .NET Framework 3.5 Enhancements Training Kit includes presentations, hands-on labs, and demos. This content is designed to help you learn how to utilize the .NET 3.5 Enhancement features including:

  • ASP.NET MVC,
  • ASP.NET Dynamic Data,
  • ASP.NET AJAX History,
  • ASP.NET Silverlight controls,
  • ADO.NET Data Services
  • ADO.NET Entity Framework."

You can download it from here.

Troy.


Categories: Resources
Posted by t_magennis on Thursday, April 17, 2008 4:32 AM
Permalink | Comments (0) | Post RSSRSS comment feed

CodeCamp 2008 Seattle Notes

I was fortunate enough to attend Code Camp in Seattle last weekend. It was great to see the event attended by around 300 keen developers.

I took notes throughout some sessions, and posted full details the HookedOnLINQ.com website.

By far, the Parallel LINQ session was a standout. I was surprised just how cleanly the ParallelFx team have committed to making multiple processor development mainstream. This is a library and feature set that is important to watch.

Troy.


Tags:
Categories: C# | LINQ | Resources
Posted by t_magennis on Thursday, January 31, 2008 4:42 AM
Permalink | Comments (0) | Post RSSRSS comment feed

LINQ Frequently Asked Questions Pages

I've been fielding lots of LINQ related questions recently through comments and emails from the HookedOnLINQ site. I decided to document my responses over the last few months and post the answers. I'd be really interested in feedback and the questions you find cropping up around the LINQ.

LINQ to Objects FAQ

LINQ to SQL FAQ

LINQ to XML FAQ

Troy.


Tags: , ,
Categories: HookedOnLINQ | LINQ | Resources
Posted by t_magennis on Friday, October 26, 2007 5:15 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Visual Studio Code-Comment Hyperlinking Add-In

I follow Brad Abrams blog and saw that he posted on a very nicely implemented Visual Studio add-in component that allows hyperlinking within code-comments.

Vance Morrison (the author of the tool) talks about making code more approachable and how he feels this type of add-in supports getting new developers understanding code faster.

Download it from CodePlex here: HyperAddIn

The main features of the HyperAddin are  

  • Anchors and Hyerlinks in your code comments.   Quickly navigate to related parts of your code by simply clicking on a hyperlink in your comments.
  • 'GoOut' Navigation.   Quickly find the method, class, and top of the file of the method you are currently in.  These places are where you should be put  interesting comments about the 'big picture' comments about the design of the code. 
  • Word wrapping in comments.  Form nicely justified paragraphs in your comments with one click of the mouse. 
  • Supports both C#, C++, JScript and VB style comments. 

Vance also asks -

If you like the capabilities of HyperAddin and wish that Visual Studio had this feature, you can vote on this here.  To vote, click on the 'Sign in to Rate' (and register if necessary), and then click on the number of stars in the rating box that corresponds to the value of this feature.   The more people who vote, the more likely this feature is to get into Visual Studio.

I'm in favor of any feature that makes code I have to maintain easier to work with. He has my vote.

Troy.


Tags:
Categories: Resources
Posted by t_magennis on Wednesday, September 26, 2007 5:18 AM
Permalink | Comments (0) | Post RSSRSS comment feed