Category Archives: .Net

WPF Hole Patterns

After I got my head above water in C# and WPF back in 2008, I created and published a sample of my first C# work that used the WPF platform for the UI. See my WPF Hole Patterns application on CodePlex to take a look at some of the vector graphics that are possible with C#, as well as how clean and pretty a WPF UI can be.

WPF Hole Patterns app is a vector based, CAD-like geometry program for laying out circular and linear hole patterns. In all, between the app and the source code, I’ve had over 100 downloads, so hopefully, it’s been helpful to some curious developers to see what they can learn from my efforts. I’ve since ported the app to Silverlight and used it as a practice field for learning the basics of the MVVM pattern. If you’d like the latest version in Silverlight, just drop me an email.

Another Example

You can also another great example (much better than mine) by checking out this Silverlight Live Geometry app on CodePlex. It’s another vector based drawing program intended to show off the Silverlight vector canvas. You can find a live version of the app at the Codeplex site, or here: http://livegeometry.com/http://livegeometry.com/

Both apps include full source code in C# and can be a helpful too in learning some geometry-based programming in C#, as well as WPF and Silverlight drawing.

Using Linq to count rows in a DataTable based on a field value

// Using Linq To DataSet to count rows based on a filter
// compared to
// Using the plain old Select() method that's been on DataTables since the beginning.
// Learn more about Linq To DataSet here: http://msdn.microsoft.com/en-us/library/bb386977(VS.100).aspx

using System;
using System.Linq;
using System.Data;
using System.Data.Common;

namespace ConsoleApplication
{
 class Program
 {
  static void Main(string[] args)
  {
   // Build up some sample data in a DataTable...
   DataTable dt = new DataTable();
   dt.Columns.Add("nMenuLevel", Type.GetType("System.Int32"));
   dt.Rows.Add(new object[] { 1 });
   dt.Rows.Add(new object[] { 1 });
   dt.Rows.Add(new object[] { 2 });
   dt.Rows.Add(new object[] { 3 });

   // Here's one way using Linq
   int linqCount1 = (from DataRow row in dt.Rows where (int)row["nMenuLevel"] == 1 select row).Count();
   Console.Write("linqCount1 = " + linqCount1.ToString() + "\n\n");

   // Here's another way using Linq
   int linqCount2 = dt.AsEnumerable().Where(c.Field("nMenuLevel") == 2).Count();
   Console.Write("linqCount2 = " + linqCount2.ToString() + "\n\n");

   // Here's a non-Linq way, using the old Select() method thats been available on DataTables
   // since the beginning. It's acutally much shorter and easier to read.
   // But watch out! Notice this Select syntaxt only requires 1 equal sign, not 2.
   int countWithSelect = dt.Select("nMenuLevel = 3").Count();
   Console.Write("countWithSelect = " + countWithSelect.ToString() + "\n\n");
   Console.ReadLine();
   }
 }
}

LINQ to SQL, Lazy Loading and Prefetching

I want to recommend this interesting article that explains times when LinqToSql’s native behavior of “Lazy Loading” is not a good thing (from a database performance standpoint), and explains a pre-fetching technique that you can can use when you want to avoid lazy loading hits to SQL Server.

It’s from the the great Rick Strahl. See his blog post at:

http://west-wind.com/Weblog/posts/38838.aspx

I also recommend that you review his LinqToSql Business Object wrapper framework and sample app that he created to show a real-world working app using the framework.

Original article and download, September 27, 2007 (read this first):

http://www.west-wind.com/WebLog/posts/160237.aspx

He also posted an update article on February 05, 2008:

http://www.west-wind.com/Weblog/posts/246690.aspx

And, Rick has continued to update the LinqToSql Business Object wrapper framework since those articles were written, and you can download the latest version which is included as part of the WestWind Web Toolkit for Asp.Net (tons of other goodies are in the entire Toolkit, so check out the free license details, which is a full working version) :

http://www.west-wind.com/westwindwebtoolkit/

 

In closing… You know, they’ve said that LinqToSql was kind of dead, but at least they did do a little work on it for .Net 4 framework. That’s encouraging to me. I think a LOT of people use LinqToSql, and I personally think it will pick up even more, rather than die off. It has a fine place in small-to-mid sized apps, and I frequently hear plenty of notables in the community speak of it.

Here’s is an article on the updates to LinqToSql that included in the .Net 4 framework:

http://damieng.com/blog/2009/06/01/linq-to-sql-changes-in-net-4

Uninstalling Visual Studio 2010 Beta 2

Why am I writing about Un-installing Visual Studio Beta 2 when it was just released yesterday, October 19, 2009? (video announcement can be seen at this link). Well, in the past whenever I’ve used the beta versions of some of Microsoft’s developer tools, I’ve found that it was impossible to uninstall them properly (or fully) when the RTM version was finally released.

Now, I know that VM’s can be used to test out beta software, and I do use VM’s on my machine, as I did when I installed VS2010 Beta 1 on a Windows 7 Beta VM running on VirualBox VM.  But sometimes I still like running right on the bare metal so I will have access to the rest of the tools I need in a full dev environment. Especially now that it’s Beta 2, I’d feel pretty good running it on my live dev machine. But, I was unsure about being able to easily remove it later when the RTM version comes out on March 22, 2010.

So, I posted a question on the Visual Studio 2010 Install and Setup forum of the newly restyled  http://www.msdn.com/forums to see if anyone could address this issue.

My question is titled Will we be able to un-install VS2010 Beta 2, when final version is released?.

Fortunately, I got a very quick reply from a MSFT moderator named Aaronru who claims a very easy and successful uninstall of VS2010 Beta 2 has been tested and WILL allow for an easy upgrade path to VS2010 RTM.

The exact reply was…

For helpful instructions on how to install Visual Studio, we’ve published some detailed instructions for installing and maintaining Visual Studio 2010 Beta 2.

If you evaluated Visual Studio 2010 Beta 1, you will be happy to hear that no reformatting is required. Additionally, simple path exists to appraise Beta 2 on the same machine. It involves uninstalling your Visual Studio 2010 Beta1 product and then installing one of the Visual Studio 2010 Beta2 offerings.  Please refer to the following blog post for more details.

As part of our Beta 2 testing, we did test the uninstall of Beta 2 to ensure that the Beta 2 could be uninstalled sufficiently to the end that you could uninstall Beta 2 and install RTM with as seamless UX as possible.

You can read the entire thread here.

So go for it! The download of VS2010 Beta 2 will be available to the public on October 21, 2009, with final RTM to be released on March 22, 2010.

Crash Course to Web Development for FoxPro and Web Connection Developers

I just received an e-mail announcement for what looks like an awesome jump start class for Visual FoxPro developers to get their feet wet in the .Net Web development arena. Super-smart web maven Rick Strahl plans to give you 3 days of quick start how-to teaching on the .Net / Web development train.

You can attend live or watch on GoToMeeting. It’s a 3-day class, November 5, 2009 through November 7, 2009.

Here is a link with all the details: http://eps-software.com/EventDetail.aspx?id=37d20fbb-6632-4264-8db5-b1665904b00a

(P.S. – Does anyone want to sponsor me?)