May 2008 Entries

Rob's Not So Lazy MVC Storefront

Rob ran into some lazy load problems in his MVC Storefront and later proclaimed: "…if you set any Enumerable anything as a property, it's Count property will be accessed when you load the parent object. This negates using any deferred loading for any POCOs, period" Rob thought this was a problem with .NET in general, but I was suspicious. Veeery suspicious. I downloaded Rob's latest bits and found some interesting behavior. Based on the screen shot of the call stack that Rob posted, it appeared LINQ to SQL was doing some type conversions. If you poke around the classes mentioned in...

Visual Designers Don’t Scale

Microsoft has a long history of being visual. They've made quite a bit of money implementing graphical user interfaces everywhere – from operating system products to database servers, and of course, developer products. What would Visual Studio be if it wasn't visual? And oh how visual it is! Visual Studio includes a potpourri of visualization tools. There are class diagrams, form designers, data designers, server explorers, schema designers, and more. I want to classify all these visual tools into one of two categories. The first category includes all the visual tools that build user interfaces – the WinForms and WebForms...

The Power of Programming With Attributes

Nothing can compare to the Real Power of programming with attributes. Why, just one pair of square brackets and woosh – my object can be serialize to XML. Woosh – my object can persist to a database table. Woosh – there goes my object over the wire in a digitally signed SOAP payload. One day I expect to see a new item template in Visual Studio – the "Add New All Powerful Attributed Class" template: * [Table]     [DataObject] [DataContract]     [Serializable] [TwoKitchenSinks]       [CLSCompliant(true)]         [DefaultProperty("Name")] [DefaultBindingProperty("Name")] [DebuggerStepThroughAttribute] [GuidAttribute("F0DD2CAA-2132-11DD-AC50-FE9355D89593")] public class Person {     [Column]             [DataMember]             [XmlAttribute]     [Browsable(true)]     [ReadOnly(false)]     [Category("Advanced")]     [Description("The person's name")]             public string Name { get; set; }     // TODO: YOUR INSIGNIFIGANT BIZ LOGIC GOES HERE... } Which begs the question – could there...

Two LINQ to SQL Myths

LINQ to SQL requires you to start with a database schema. Not true – you can start with code and create mappings later. In fact, you can write plain-old CLR object like this: class Movie {     public int ID { get; set; }     public string Title { get; set; }     public DateTime ReleaseDate { get; set; } } … and later either create a mapping file (full of XML like <Table> and <Column>), or decorate the class with mapping attributes (like [Table] and [Column]). You can even use the mapping to create a fresh database schema via the CreateDatabase method of the DataContext class.LINQ to SQL...

Mr. President the Programmer

Daily Standup Transcription 06 May 2008 1300 Zulu Time In 00:02:34.66 "… so, yesterday I continued the refactorafication of some classes. The job isn't easy, but I'm going to work hard and continue the collaborativity with my programming partner. Together, we will eliminate the evil of legacy code operating inside the code base. I know it's been slow going, but we did misundestimerate the threat of static ... static … statictistical dependencies in the code. Now, if you'll excuse me, I need to get back to work for the great customers of this company." Time Out 00:02:54.29

There Is Always Risk In Portability

After my last post, someone asked me if the "portable" repository pattern was really a good idea. He was referring to the fact the LINQ queries in the MVC Storefront and Background Motion applications would sometimes execute against in-memory collections (for unit testing), while the rest of the time the queries would execute against a relational database. Isn't there a huge risk in developers not knowing if the software really works with the database? I don't think of the repository as a "portability" layer, although since it is an abstraction layered on top of the data access code it can provide...

Contrasting Two MVC / LINQ to SQL Applications for the Web

There are two applications on CodePlex that are interesting to compare and contrast. The MVC Storefront and Background Motion. MVC Storefront MVC Storefront is Rob Conery's work. You can watch Rob lift up the grass skirt as he builds this application in a series of webcasts (currently up to Part 8). Rob is using the ASP.NET MVC framework and LINQ to SQL. The Storefront is a work in progress and Rob is actively soliciting feedback on what you want to see. At the it's lowest level, the Storefront uses a repository type pattern. public interface ICatalogRepository {     IQueryable<Category> GetCategories();     IQueryable<Product> GetProducts();     IQueryable<ProductReview> GetReviews();     IQueryable<ProductImage> GetProductImages(); } The repository...

The XML Namespace Tax

While XML literal features in Visual Basic get all the love, the new XElement API for the CLR makes working with XML in C# a bit more fun, too. It's a prime cut of functional programming spiced with syntactic sugar. One example is how the API works with XML namespaces. When namespaces are present, they demand attention in almost every XML operation you can perform. It's like a tax you need to pay that doesn't pay back any benefits. An old poll on xml-dev once asked people to list their "favorite five bad problems" with XML, to which Peter Hunsberger...

Mocks - It's A Question Of When

Ross Neilson reminded me about a question I left hanging - "when should I use a mock object framework?" If you have to ask "when", the answer is probably "not now". I feel that mock object frameworks are something you have to evolve into. First, we can talk about mocks in general. Some people have a misconception that mock objects are only useful if you need to simulate interaction with a resource that is difficult to use in unit tests - like an object that communicates with an SMTP server. This isn't true. Colin Mackay has an article on mocks...