Powered by discountASP.NET
referal ID: sdtref
Why recommend discountASP.NET?

Archives
Steve Trefethen Steve's RSS Feed Subscribe or via email
What's this?
Contact me Send mail to the author(s)
About Me
View my LinkedIn profile

Add to Google
Subscribe with Bloglines
MCP Microsoft Certified Professional

Falafel Software
ActiveFocus Project Management Solution by Falafel Software
Online or OnSite TestComplete Training
Blogroll
Recent Comments
My Online Tools
Stats
Total Posts: 441
This Year: 46
This Month: 2
This Week: 0
Comments: 1526
Tags
Disclaimer
The posts on this weblog are provided �AS IS� with no warranties, and confer no rights. The opinions expressed herein are my own personal opinions and do not represent my employer�s view in any way.
 Tuesday, April 15, 2008

C# Source Code Formatting Preferences

Posted @ 1:37AM by Steve Trefethen

Categories: .NET | Opinion | Programming

Tags:  |  | 

I just tried checking in some C# code and ran into a merge error so I fired up Araxis Merge and noticed hundreds of unexpected changes all to whitespace! That was a bummer because I just wanted to check in and call it a night but alas, it’ll have to wait a day. Now, I know code formatting can be a religious issue but...

Here are a few examples, the actual code of which is unimportant for the purposes of this discussion:

1 public void foo(string locator) { 2 try { 3 if (selenium.IsElementPresent(locator)) 4 break; 5 } catch (Exception) { 6 } 7 }
and
1 public void foo(string locator) 2 { 3 try 4 { 5 if (selenium.IsElementPresent(locator)) 6 break; 7 } 8 catch (Exception) 9 { } 10 }

I’d call the latter more "mainstream" as the majority of Open Source projects I’ve looks at (including dasBlog, FileHelpers, RssToolkit, SubSonic, CCNET and SubText) all seem to align the braces with a few exceptions like the empty catch block or a single statement block. I haven’t downloaded the .NET sources yet but I’d be interested to know what Microsoft uses.

Chuck Jazdzewski, a well known 'softie publishes a good deal of C# code on his blog formatted using the top style. A few colleagues, John Waters, Falafel's CTO and Adam Andersen have both blogged using the latter style, here and here respectively.

Which do you prefer? Do you consider either more "mainstream" than the other?

[Update: April 15, 2008] Added a list of OS projects I've looked at.
 Wednesday, January 23, 2008

NDepend and static code analysis for .NET

Posted @ 12:25AM by Steve Trefethen

Categories: .NET | Development | Tools

Tags:  |  | 

Recently, I’ve been spending time analyzing code from a project I’m working on using NDepend 2.6. NDepend is described as...

...a static analyzer that simplifies managing complex .NET code bases.

It digs deep into your code providing an incredible level of detail. Should you decide to take a look at NDepend be sure to give yourself several hours to spelunk as there’s tons to dive into. For starters here is a screenshot of what you can expect when you load a project:

NDepend Static Code Analysis Tool

In this image the mouse (not pictured) is hovering over an assembly name in the Dependencies pane, in the center of this image. Simultaneously the assembly region is is highlighted in the Metrics pane, in the top right.

Querying your code

While I’m still very new to this tool and digging away the thing that’s really caught my attention is CQL. Here’s a closer look at the CQL Query pane:

NDepend CQL Queries Pane

CQL stands for Code Query Language and it’s exactly what it sounds like, SQL for code, the heart of NDepend. In fact, you can check out the CQL v1.5 spec. In the above image, the queries you see are provided by default when you load a new project. On the left is a list of query groups which is a one to many with the queries listed on the right. In the image at the top I’ve selected a query titled "Methods too big" which equates to this in CQL:

// <Name>Methods too big (NbLinesOfCode)</Name>
WARN IF Count > 0 IN SELECT TOP 10 METHODS WHERE NbLinesOfCode > 30 ORDER BY NbLinesOfCode DESC
// METHODS WHERE NbLinesOfCode > 30 are extremely complex and
// should be split in smaller methods
// (except if they are automatically generated by a tool).
// See the definition of the NbLinesOfCode metric here http://www.ndepend.com/Metrics.aspx#NbLinesOfCode

Notice the blue highlights on the Metrics pane, again the one with the gray sphere’s, which represent methods from the query result set. Double clicking any of the sphere’s opens that method in VS.NET, very nice. Btw, NDepend includes copy/paste syntax highlighting of CQL queries, also a nice touch.

NDepend CQL Intellisense

Clearly, CQL is incredibly powerful and the engine that drives the code analysis used in NDepend. I think it’s a very natural approach for .NET developers and if you’ve worked with SQL at all you’ll find picking up CQL straightforward. Although, NDepend does go one step further by providing CQL Intellisense making it easier to get started with the new query language.

While the Intellisense support is nice it would be even better if it listed things like assemblies, namespaces and types (among others) where appropriate rather than just listing "assembly" or "type".

Continuous Integration Support

If you’ve followed my blog you know I’ve written quite a bit about CruiseControl.NET which NDepend integrates nicely with. Included is a command line tool which will generate your NDepend output for integration with your build results. Here is a short screencast available with more details so I’ll leave it at that.

Conclusion

I’ve already spent numerous hours exploring my code and playing with CQL and I still just scratching the surface. I’ve also managed to find and fix a number of issues and improve and optimize my code. The NDepend website has lots of screencasts on how to accomplish various tasks using NDepend and be sure to read Patrick’s blog for lots more information on NDepend.

What do you use for static code analysis?

In the interest of full disclosure, I was provided a copy of NDepend v2.6.3 for review with no strings attached for which I’d like to thank NDepend’s developer Patrick Smacchia for the license and providing such a great tool to the .NET community!

 
ActiveFocus.netActiveFocus
UNITING TEAMS FOR PEAK PERFORMANCE
Web base Project Management Software
Click here for pricing as well as hosting options
View the roadmap
Ad by Falafel Software
 Sunday, December 09, 2007

Using CruiseControl.NET to manage EDI Invoice processing

Posted @ 11:07PM by Steve Trefethen

Categories: .NET | Development | Open Source

Tags:  |  | 

A few months ago I started working in an area I previously knew little about, EDI. EDI stands for Electronic Data Interchange and it defines standards for how businesses communicate with one another electronically. The basic flow of information for what I’m working on looks like this:

  EDIDiagram
The document numbers above correspond to the following:

  • EDI 850 = Purchase Order (PO)
  • EDI 810 = Invoice
  • EDI 997 = Functional Acknowledgement

My client represents the seller’s side of this diagram and I’m specifically working on the lower half of this picture, the invoicing portion, as there is existing software which handles PO’s. As indicated in light red there is a trading partner involved which brokers various services between buyers and sellers including providing EDI services. The EDI "documents" are cryptic delimited text files exchanged via numerous transport mechanisms though FTP is used in this case.

The Flow

Basically, there is a system which polls the trading partner, again via FTP, looking for new purchase orders. When one is found the file is downloaded, validated, processed and an acknowledged (EDI 997) is transmitted back to the trading partner. Eventually, the order works it’s way through the system and an invoice is generated at which point, an EDI 810 is generated and transmitted to the trading partner, validated and again acknowledged with an EDI 997, a mirror image of the EDI 850 processing. For brevities sake I’m glossing over parts of this process but you get the gist of what’s going on.

When I first was assigned to start working on EDI invoicing I had a lot of things to learn including EDI, the current processes involved in invoicing and the software that handled purchase orders among others. I quickly learned via not so subtle hints that the existing software which handles PO’s wasn’t considered maintainable and is badly in need of replacement.

Using CruiseControl.NET

Once I got my feet grounded I realized this system closely resembled a continuous integration process and started investigating using CruiseControl.NET as the primary engine to drive invoice handling. I already knew CruiseControl.NET brought a number of interesting features to the table including:

  • Open Source
  • Polling architecture for trigging task execution
  • Open plug-in architecture for things like source control providers and task execution
  • Easily configured using XML (ccnet.config)
  • A customizable web based portal for monitoring projects
  • Email publishing for notifications
  • Logging

Basically, you can envision CruiseControl.NET as the two blue circular arrows in the middle of the above diagram. In a future, post talk more about the specific implementations of ISourceControl and ITask that I’ve written to manage this EDI process.

 Thursday, November 01, 2007

Processing CSV files in C# using Open Source FileHelpers Library

Posted @ 1:39AM by Steve Trefethen

Categories: .NET | howto | Open Source | Programming

Tags:  |  |  | 

Scott Hanselman recently posted about parsing CSV files from PowerShell and while I found it interesting I didn’t find the solution to be intuitive though perhaps that’s just me. I’ve recently purchased PowerShell in Action by Bruce Payette and I like the idea of PowerShell though I find myself bailing back to a plain old Command Prompt quite frequently. Anyway, a few days ago I blogged about using the Open Source FileHelpers library for parsing fixed and delimited length files. I thought it might be fun to tackle Scotts problem and see just how difficult it would be to duplicate his solution in C#. Here is what he was parsing (at least a snippet of it anyway):

"File","Hits","Bandwidth"
"/hanselminutes_0026_lo.wma","78173","163625808"
"/hanselminutes_0076_robert_pickering.wma","24626","-1789110063"
"/hanselminutes_0077.wma","17204","1959963618"
"/hanselminutes_0076_robert_pickering.mp3","15796","-55874279"
"/hanselminutes_0078.wma","14832","-1241370004"
"/hanselminutes_0075.mp3","13685","-1840937989"
"/hanselminutes_0075.wma","12129","1276597408"
"/hanselminutes_0078.mp3","11058","-1186433073"

With FileHelpers the first thing to do is define a class that maps the data in your file which for Scott’s data would look something like this:

    [DelimitedRecord(",")]

    class Show

    {

        public string Filename;

        [FieldConverter(typeof(IntConverter))]

        public Int32 downloads;

        [FieldConverter(typeof(IntConverter))]

        public Int32 bandwidth;

    }

Notice the class attribute indicates the separator used. Also notice the member attributes that provide string conversion for the integer values read from the file. Since the integers, unfortunately, have quotes the stock FileHelpers converter won’t work though that’s easily solved by writing a new IntConverted like this:

    public class IntConverter : ConverterBase

    {

        public override object StringToField(string from)

        {

            if (from != "" || from != "\"\"")

                return Convert.ToInt32(from.Substring(1, from.Length - 2));

            else

                return string.Empty;

        }

    }

For parsing the file we use FileHelpers DelimitedFileEngine like this:

     DelimitedFileEngine e = new DelimitedFileEngine(typeof(Show));

     e.Options.IgnoreFirstLines = 1;

     object[] shows = e.ReadFile("c:\\shows.txt");

This creates an instance of the engine passing our Show class type with an option to ignore the first line of the file (the one with column headings). Calling ReadFile parses it into and array of Show objects populated with the data. Next, we’ll change the filename to the episode number using Scott’s regex and sort the data both using anonymous delegates:

    Regex regex = new Regex("\\d{2}(?=[_.])");

    Array.ForEach((Show[])shows, delegate(Show one)

        { one.Filename = regex.Match(one.Filename).ToString(); }

    );

    Array.Sort((Show[])shows, delegate(Show one, Show two)

        { return one.Filename.CompareTo(two.Filename); }

    );

Finally, we sum the downloads and print the data. Note this for loop modifies the array using the first instance of an episode to aggregate the total downloads, perhaps not optimal but gets the job done:

    Show sh = (Show)shows[0];

    for (int i = 1; i < shows.Length; i++)

    {

        if (((Show)shows[i]).Filename.CompareTo(sh.Filename) == 0)

            sh.downloads += ((Show)shows[i]).downloads;

        else

        {

            Console.WriteLine("{0,-4} {1,-6}", sh.Filename, sh.downloads);

            sh = ((Show)shows[i]);

        }

    }

    Console.WriteLine("{0,-4} {1,-6}", sh.Filename, sh.downloads);


So, what’s the point? Well, at the end of Scott’s post he wrote:

It took less time than it would take to write a C# program and it’s easily modified ad-hoc.

Armed with FileHelpers this took no time at all, the bulk of the code is spent working with the data not importing into a usable form. Another point is, IMO the C# code is considerably easier to read. I’m finding that getting my head around PowerShell commands to be a bit awkward. For me PowerShell is tantilizingly powerful but I feel requires a different enough mind set to perhaps thwart rapid adoption. I can empathize with all those people who have "been meaning to try..." Of course, I suppose if we all had the chance to sit down with Lee Holmes things might be different.
 Tuesday, October 30, 2007

Microsoft's interesting "embrace" of Windows Open Source

Posted @ 12:54AM by Steve Trefethen

Categories: .NET | dasBlog | Open Source

Tags:  |  | 

If you follow Microsoft’s web development world you might have noticed an interesting trend dating back to January of this year. You see, back in January they hired RubyCLR guru John Lam. In July they hired top tier (.NET) blogger and lead developer of the dasBlog open source blog engine Scott Hanselmen. More recently they’ve hired Phil Haack, lead developer for SubText another .NET blog engine and now they’ve hired Rob Conery the developer of SubSonic.

It’s possible and perhaps the hiring trend extends further back than January although these four hires alone seem fairly significant in the realm of .NET based OS software. It makes me wonder if perhaps Jeff Atwood is next? He just finished writing An ASP.NET 2.0 Anthology with none other than Phil Haack (and a few others) and already has a deal with Microsoft where they’ll match his OS donations. Of course, ScottGu is a big blogger and he personally reached out to Rob Conery so it wouldn’t surprise me if Scott and his crew have "gone shopping" for people who are influential .NET bloggers as well as OS developers. In fact, Rob talked about the significance of keeping his blog as well as his SubSonic work alive and I’m sure similar conversations occurred with ScottH and Phil.

To top it all off, check out this email from last May that Clemens Vasters (the original dasBlog developer) sent to the dasBlog developer’s mailing list. Here is a quote from that message.

"The purpose of this work is, as indicated, to use the engine as a testbed for a lot of new technologies we’re bringing online in RTM or Beta form over the course of the next several months. The current intent is to have all dasBlog-based bloggers from our division here at Microsoft and also the one or the other official "team blog" run on that testbed."

I’ve been using dasBlog for about a year now and I really like it so all this attention will be interesting to watch. I wonder what it means for SubText?

 Sunday, October 28, 2007

Subsonic DAL now backed by Microsoft

Posted @ 10:02PM by Steve Trefethen

Categories: .NET | DAL | Open Source

Tags:  |  | 

I first mentioned SubSonic, a .NET DAL framework, almost a year ago in a post discussing my decision regarding a DAL framework for use in an ASP.NET project I was working on. When I made my decision Subsonic was in it’s very early stages of development but peaked my interest nonetheless. I think it’s interesting that a little over a week ago I decided to use SubSonic for a project at work and now Rob Conery, Subsonic’s primary developer, has joined Microsoft to continue development as part of the new MVC framework.

If you haven’t looked at SubSonic, it’s well worth a try particularly if your database consistently makes use foreign keys allowing for the generated object model to provide deep navigation capabilities for lookup field values etc. I’m working on a large ERP system with a database of 300+ tables and generating a SubSonic assembly took only a few minutes. At any rate, it’s always nice when an OS project you’ve chosen receives this sort of backing offering at least some reassurance.

[UPDATE: Jan 10, 2007] Fix spelling of Rob's name.

 Tuesday, October 23, 2007

Solution file warning MSB4051 GUID was not found in the .SLN file

Posted @ 11:35AM by Steve Trefethen

Categories: .NET | Continuous Integration | Development

Tags:  |  | 

We’re using CruiseControl.NET with an MSBuild task to build the solution file for a large ERP system which includes 21 .csproj files and recently when some code was moved to a new project the build started failing with this error:
Velocity.sln : Solution file warning MSB4051: Project {958E0376-0272-4149-A1CF-E03521D12A72} 
is referencing a project with GUID {14F4138C-4DA7-4029-A8D3-B1B3954C2839},
but a project with this GUID was not found in the .SLN file.

The weird thing is that from within VS.NET the project would build just fine. It turns out that the .sln file was missing "EndProject" line just above the GUID mentioned. Here is the fragment of the .sln file with the problem (fyi, I’ve wrapped the two project lines):

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VelocityProductionPlanning", 
"VelocityProductionPlanning\VelocityProductionPlanning.csproj",
"{4BAFD59F-EBB5-4FDA-8639-F7FC63F7F351}"
ProjectSection(WebsiteProperties) = preProject
  Debug.AspNetCompiler.Debug = "True"
  Release.AspNetCompiler.Debug = "False"
EndProjectSection
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VelocityLibraryMessaging",
"VelocityLibraryMessaging\VelocityLibraryMessaging.csproj",
"{14F4138C-4DA7-4029-A8D3-B1B3954C2839}"
EndProject

Notice, the project VelocityProductPlanning has no "EndProject" line. That caused MSBuild to generate the above warning and subsequently the build to fail.

Hope this helps.

Processing fixed length or delimited files quickly and easily in .NET

Posted @ 1:22AM by Steve Trefethen

Categories: .NET | Open Source | Tools

Tags:  |  | 

I recently ran into a really useful Open Source project called FileHelpers by Marcos Meli. FileHelpers is a .NET library used to import and export data to/from fixed length or delimited text files. The library is highly customizable with good documentation, lots of examples and a record class wizard to help you build classes that match your data.

FileHelpers record class wizard screenshot

It even supports master detail as well as multi-record mappings making it easy to work with all sorts of structured flat file data.

I’ve been working on a large ERP system and I’m currently focused on adding support for EDI Invoicing. EDI is a set of standards for structuring data that’s passed electronically between trading partners. EDI files are structured plain text files and I’m currently investigating FileHelpers MultiRecordEngine class for use with producing and consuming EDI files. I’ve only spent a few hours so far and I already have basic reading and writing of EDI 810 Invoices working.

One thing I did want to mention is that the example on the site for hooking up events is incorrect so here is an example of subscribing to the AfterWriteRecord event:

m_engine = new MultiRecordEngine(GetSelector(), GetRecordTypes()); m_engine.AfterWriteRecord += new EventHandler<AfterWriteRecordEventArgs<object>>(AfterWriteRecord); private void AfterWriteRecord(object sender, AfterWriteRecordEventArgs<object> e) { ... }
 Tuesday, July 31, 2007

Automated testing of ASP.NET web applications using Selenium

Posted @ 1:06AM by Steve Trefethen

Categories: .NET | AJAX | ASP.NET | Automation | Continuous Integration | Firefox | IDE | Open Source | Quality | Recommended | Testing | Tools

Tags:  |  |  |  |  |  |  |  |  |  |  | 

Lately, I've been focused on Web Application testing frameworks and I've been looking at a number of different options and having varying degrees of success. That is, of course, until I started looking at Selenium after Lino mentioned it to me and I'm very impressed. Selenium is an open source project with multiple tools designed for testing web applications. Selenium includes:

  • Selenium IDE an add-on to Firefox use for recording test scripts
  • Selenium RC (Remote Control) a Java server used for execution of test scripts
  • Selenium Core client side testing support for web applications added directly to your application
All of these are interesting in their own right so be sure to look closely at each piece.

Selenium IDE

Selenium IDE
The Selenium IDE is a non-modal dialog add-on for Firefox that supports Selenium test development. In fact, it's more than fair to call this single dialog an IDE because it fully supports recording, development and debugging of test scripts. Additionally, it can format test scripts in any of the following for use with Selenium RC:
  • HTML
  • Java
  • C#
  • Perl
  • PHP
  • Python
  • Ruby

A Selenium test script consists of a series of Commands which have a Target and optionally a Value. For example, browsing to a web page using Selenium consists of the following:

Command: open
Target: http://localhost/myapp

To click on a link titled "About" on a page the Command might look like this:

Command: clickAndWait
Target: link=About

This will initiate the click and wait until the new page is done loading. There are literally hundreds of commands to choose from covering input (both keyboard and mouse), control manipulation, drag/drop, evaluation, verification, waiting, browser manipulation and just about anything else you'll need.

If you've done any UI testing at all you're familiar with the challenge of manipulating a UI programmatically in a manner independent from of the size, position or location of the control you're trying to manipulate. Selenium solves this problem using XPATH and providing the ability to locate controls based on XPATH expressions alleviating the need to hard code HTML tag structure into a test script. This is particularly crucial for ASP.NET testing since the runtime mangles the ID attributes of rendered tags. For example, the ASP.NET runtime may render ID attributes that look like:

id="ctl00_cphContents_gridMaint_DataGrid"

Finding this control using an XPATH expression can be simplified to something like this:

//table[contains(@id, "gridMaint")]

In the event the nesting of the DataGrid changes the script will continue to function properly as long as table's ID contains the text "gridMaint".

Example of using the Find button on the Selenium IDE

Notice the link is highlighted in the browser

Playing back tests using Selenium TestRunner

The Selenium IDE has a toolbar button that will launch a feature called TestRunner which allows you to playback your tests using controls hosted in an IFRAME inside your browser. Here's what it looks like:

Selenium TestRunner

You can playback your entire test from right within your browser. It's like having the IDE built right into your application.

Selenium RC

Next, is Selenium RC which is a Java server application used execute Selenium tests and drive a browser instance through AJAX communication with the browser. To start Selenium RC simply execute the following from a command prompt:

java -jar selenium-server.jar -interactive

Since I'm focused on .NET I'll discuss the C# approach. Once you've recorded and debugged your test you can capture it as C# and compile it into an NUnit compatible assembly where upon execution it will drive Selenium RC to manipulate the web application through a browser instance running on your desktop. Here is an example of the above recorded test in C#:

1 using System; 2 using System.Text; 3 using System.Text.RegularExpressions; 4 using System.Threading; 5 using NUnit.Framework; 6 using Selenium; 7 8 namespace SeleniumTests 9 { 10 [TestFixture] 11 public class NewTest 12 { 13 private ISelenium selenium; 14 private StringBuilder verificationErrors; 15 16 [SetUp] 17 public void SetupTest() 18 { 19 selenium = new DefaultSelenium("localhost", 4444, "*firefox", 20 "http://localhost:4444"); 21 selenium.Start(); 22 verificationErrors = new StringBuilder(); 23 } 24 25 [TearDown] 26 public void TeardownTest() 27 { 28 try 29 { 30 selenium.Stop(); 31 } 32 catch (Exception) 33 { 34 // Ignore errors if unable to close the browser 35 } 36 Assert.AreEqual("", verificationErrors.ToString()); 37 } 38 39 [Test] 40 public void TheNewTest() 41 { 42 selenium.Open("/selenium-ide/"); 43 selenium.Click("link=About"); 44 selenium.WaitForPageToLoad("30000"); 45 } 46 } 47 } 48

Generation of NUnit compatible tests is great because it makes it really easy to incorporate Selenium test suites into a continuous integration environment like CruiseControl.NET.

Conclusion

If you're in need of a web application testing framework you owe it to yourself to check out Selenium. I'd go so far as to say if you're doing doing any web related development and you're not already using Selenium you should stop right now and go download it. Here are there RSS feeds.

After playing with Selenium for about an hour I was easily able to:

  • Record tests against a RIA
  • Build a C# NUnit compatible assembly to drive Selenium RC
  • Integrate the tests into an automated build using CruiseControl.NET

Since then I've been able to really dig in and accomplish a lot of work in a very short period of time. The next step is to build up a nice battery of tests and dig into NCover to help figure out where the holes are.

Lastly, I just want to tip my hat to the ThoughtWorks and volunteers and supporters of the Selenium project. Kudos for such a great framework!

 Friday, January 19, 2007

Delphi ASP.NET AJAX demo fixed on CodeCentral

Posted @ 10:23AM by Steve Trefethen

Categories: .NET | AJAX | ASP.NET | Delphi

Tags:  |  |  | 

Doh! I just realized one of the Delphi ASP.NET AJAX demos I posted to CodeCentral is missing the actual download zip file. I just fixed the problem so if you're interested you can get it here: Updated: I just uploaded both of these demos to my website so now you can actually see the Delphi versions live (yet another advantage of hosting my own blog). Here are the links: Update: Fixed the spelling of Delphi in this blog entry (doh!)
 Monday, November 27, 2006

Adapdev update

Posted @ 11:29PM by Steve Trefethen

Categories: .NET | DAL | ORM

Tags:  |  | 

Recently, I blogged about some of the Open Source .NET DAL implementations I've worked with and mentioned Adapdev whose primary developer is Sean McCormack. Sean had posted a message to the Adapdev blog about slowing development but this morning while I was reading through my blog feeds I found this post explaining that the slow down didn't really materialize and mentioning some nice updates to several of the projects related to Adapdev.NET. Sean also mentioned that he's nearly completed a new ORM framework called Elementary which I'll be very interested to look at.

 Tuesday, November 21, 2006

Data Access Layers (DAL) on the .NET framework

Posted @ 8:33AM by Steve Trefethen

Categories: .NET | DAL

Tags:  | 

A Data Access Layer, commonly referred to as a "DAL" is code that provides the ability to view, edit, update and otherwise manipulate persistent data within an application. In many cases, a DAL can be generated from a database schema and alleviates developers from the task of writing highly repetitive code. All of the DAL's I've looked at have benefits and detractors so the task of actually selecting the perfect implementation isn't straight forward and will depend on the application requirements as well as the developers ability work with the given DAL implementation.

There are lot's of DAL implementations available like:  

There are many others but the above list represents ones I've either experimented with or actually used with the one exception being CLSA.NET which I've seen mentioned in numerous places and thus why included it.

A few months ago SPOIL implementation in particular caught my eye and seems quite interesting. In fact, I did some digging on this one and found that a BorCon speaker Steve Scott presented the same idea at BorCon 2003 and even before that Atif Aziz had developed DBMethods though there is no mention of it in the MSDN article (referenced above) but I did find an interesting comment from Atif. For a website I've been working on over the past few years I chose to use CodeSmith 2.6 which is a freeware code generator specifically for it's "collection of database templates" which are included in the download. These templates provide several pieces of the DAL puzzle including:

  • Stored Procedure generation for all CRUD operations
  • Command wrappers for the above stored procs
  • Typed datasets
  • Business Objects
  • Typed collections

Of course, lots of things have changed since I made my choice, CodeSmith is up to version 4.0 and now sold commercially and AFAICT garnered quite a following not to mention .NET 2.0 was new at the time and there wasn't a whole lot of support for it. Additionally, the templates were subsequently updated to utilize C# 2.0 features like generics. CodeSmith is an easy to use code generation tool that has an interesting template technology that borrows techniques from ASP.NET. I'll admit it took me awhile to convince myself that I needed to go this route at all but eventually I was satisfied with the decision. I'd have probably gone in a different direction today though I don't really feel locked into the decision I made since the code is fairly boiler plate and it wouldn't be that difficult to switch to another DAL.

A couple of months ago I spent quite a bit of time looking into Adapdev and it's supporting tools Codus, a code generator and Zanebug a unit testing tool. It's really a nice combination and allows you to quickly generate a DAL and immediately test it allowing you to quickly locate problems. The developer Sean McCormack has been very responsive to bugs and even quickly turned around a fix for a significant problem I had run into. Unfortunately, he has recently blogged about a slowdown in the development though I think it's still well worth a look.

I don't want to ramble on too long so I'll wrap it up by saying that I've had some good success finding very useful DAL implementations though I have yet to find one that has really addressed all of my needs. If you've been doing similar work I'd be interested to know what's worked for you.

Update: Paul Hectors made the comment that CSLA.NET is a Business Object framework and not a DAL implementation. He's right. Here is a link that explains what CSLA.NET is from the author himself. Thanks for the correction Paul.

[UPDATED: April 25, 2008] Related post:

 Wednesday, March 09, 2005

Richard Grimes questions .NET's future

Posted @ 10:13AM by Steve Trefethen

Categories: .NET

Tags:

In this article Richard Grimes (DDJ magazine contributor) makes some interesting points about the .NET framework. I don't know that I agree with them but it's good to get a grasp on the issues from many different points of view. In particular, I was interested in the comments relating to VB.NET and ASP.NET.
[Update: March 9, 2005] As I'm reading through my Bloglines I discovered that Allen Bauer has also mentioned this article.