Friday, August 24, 2007

LINQ to DataSets

Erick Thompson has posted an article on LINQ to DataSets. It's a great primer on LINQ querying ADO.Net DataSets. 

Thursday, August 23, 2007

LINQ misconceptions

 Time and time again I heard coworkers  that "X" (insert your favorite ORM tool) is far superior to LINQ in regards to ORM and time and again LINQ is not really about ORM. Yes LINQ to SQL has some ORM type features, but it's not really a pure ORM platform.

  LINQ is really, at least in my opinion, about the language query functionality. It gives .Net programmers the power to write queries against not only SQL objects but native objects and XML in a language they are comfortable working in.  LINQ really shines in when used to query object collections and XML, operations that would have previously taken a dozen lines of code and nested loops is now as simple as a query. To me that is the power of LINQ.

  Yes the SQL database modeling and LINQ to SQL is equally as compelling, but I think people are to wrapped up thinking in terms of ORM tools that the miss the real functionality or how it can be leveraged to solve real business problems today.

 So next time you here someone comparing LINQ to ORM, tell them it's not about ORM, it's about the query.

Monday, August 13, 2007

LINQ file info code

 Here is a LINQ sample in C# based on the VB.Net How Do I? videos. To set this up create a simple windows form application, add a DataGridView and dock it to the form.

Place the following code in the form load event handler:

System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();

      watch.Start();

           var files = (from  file in Directory.GetFiles(Application.StartupPath)
              select file);

           var fileInfo = (from file in files
                          select new FileInfo(file));

           var myFiles = from file in fileInfo
                         select new FileOps { Creation = file.CreationTime, Name = file.Name };

           dataGridView1.DataSource = myFiles.ToList();

           watch.Stop();

           TimeSpan ts = watch.Elapsed;

           MessageBox.Show(String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
               ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10));

 

To use the object initializers with anonymous types add the following class nested in the form class:

public class FileOps
  {
      public string Name { get; set; }
      public DateTime Creation { get; set; }
  }

 

You'll notice we start looking in the application startup directory, just replace it with the directory of your choice to try other directories. You can comment out the timing code if you just want to run the sample without a message box.

Enjoy................

Wednesday, August 8, 2007

The declining value of customer loyalty

 I've been weighing the benefit of renewing my Infragistics NetAdvantage subscription over the past couple of weeks and I think for the first time since 2002 I will not renew may subscription.

  Here's the issue, I've been a loyal customer since 2002, provided feedback, reported bugs and endorsed the product to co-workers and manages. My managers have always went and purchased company licenses on my recommendation.  I really like the tools overall and they generally add value each release. That said, last year early renewal was $335 which is expensive but not unreasonable, this year $445, a hundred dollars difference. They also like to send the renewal requests incrementally, 20% then 10% then nothing off all about 30 days apart, seems to me it should be the other way around, 10% then 20% to keep loyal customers. 

  The price isn't the only issue. I used to receive notice of new releases and upcoming betas,now I get nothing. I actually asked why this was on their PM's blog, the answer was that they may not have a current email address. That's funny because they can certainly reach me for a renewal request.

  So I'm going to start looking around for something comparable for another vendor, one who may actually value loyal customers. 

Monday, August 6, 2007

.Net 3.5 gems

 So often when a new release of the .Net framework is upon us we hear about the new "shiny" pieces, which while important, doesn't convey the fact that other parts of the framework are receiving attention as well.

  A case in point is the OpenFileDialog, I noticed some new properties for SafeFileName and SafeFileNames which weren't there in 2.0. I'm sure there are a bunch of other enhancements and additions, some like these are probably there to support Vista.

 At any rate my hats off to the guys/gals who add the non "shiny" parts that make our jobs easier on a daily basis.  

Saturday, August 4, 2007

Visual Studio 2008

 I've had a chance now to spend a fair amount of time with Visual Studio 2008 and so far has been solid. Right now I'm spending a lot of time getting familiar with all the new C# 3.0 features. It's always a lot of work staying ahead of the changes. So far my favorite IDE enhancement has to be the WPF editor, it's come a long way since it's preview days. My favorite language feature has to be Linq or Language integrated query. This is a great addition and it has made one of those often tedious tasks easy.

 More than once I've had to compare the contents of two lists to determine what exists in one that isn't in the other. I'm currently working on an app that imports a file, this file is always appended to, so I just need to add the new items to my collection, linq makes it a snap, here's the code.

IEnumerable<string> entryQuery =
          (from s1 in entries
           select s1).Except
            (from s2 in currentEntries
             select s2);

           //update the current entries to reflect the additions
           foreach (string s entryQuery)
           {
               currentEntries.Add(s);
           }

I've seen and implemented Equals on the collection, but most of the time you end up with the same record multiple times, with linq on one copy of any item is added.

Friday, July 27, 2007

Orcas Beta 2

Microsoft has released beta 2 of Orcas You can download it from here. This release is really coming along in terms of functionality and usability especially the WPF editor.