PLINQO - CodeSmith LINQ to SQL Templates

PLINQO, which stands for Professional LINQ to Objects, is a collection of CodeSmith templates that are meant to replace and extend the LINQ to SQL designers that are included with Visual Studio 2008.


  • Generate or update a LINQ to SQL dbml file from a database schema.
    • Includes all tables, stored procedures, functions, and views with the ability to exclude objects based on regex patterns.
    • Ability to automatically remove object prefix and suffixes (ie. tbl_ and usp_).
    • Dbml file can still be customized with the normal Visual Studio 2008 designer.
    • Dbml file can be refreshed based on the current database schema without losing customizations. (See Safe Attributes)
  • Generation of the LINQ to SQL DataContext class.
  • Generation of the LINQ to SQL entity classes.
    • Generates one file per entity instead of one massive file.
    • Generates partial classes where custom code can be written and won’t be overwritten.
    • Generated entity files are added to the project as code behind files to their corresponding custom entity files.
  • Generation of entity manager classes.
    • Adds customizable business rules engine to enforce entity validation, business and security rules.
    • Provides access to common queries based on primary keys, foreign keys, and indexes.
    • Common queries are exposed as IQueryable so they can be extended.
  • All templates can be customized to meet your needs.

Read More


Easier way to page Linq queries.

The following query extension will make paging a query more natural then skip and take. Simply append Paginate(page, pageSize) to your query.

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

namespace System.Linq
    public static class PageQuery
         public static IQueryable<T> Paginate<T>(
            this IQueryable<T> query, int page, int pageSize)
            int skip = Math.Max(pageSize * (page - 1), 0);
            return query.Skip(skip).Take(pageSize);

Calculator.NET - Calculator that evaluates math expressions

I’d like to announce the release of a little project I’ve been working on. I call it Calculator.NET. I started this project for a couple reasons. First, I was annoyed that Windows Vista doesn’t come with a better calculator. Windows XP has Power Calculator, but that doesn’t work on Vista. Next, I was reading a blog about DynCalc by Bart De Smet on how to do mathematical calculations. That gave me the starting point on how to create Calculator.NET.

As part of the project, I created a MathExpressions library that does the bulk of work. The library supports math expressions, functions unit conversion and variables. Below are some examples of using the library directly.

MathEvaluator eval = new MathEvaluator();
//basic math
double result = eval.Evaluate("(2 + 1) * (1 + 2)");
//calling a function
result = eval.Evaluate("sqrt(4)");
//evaluate trigonometric 
result = eval.Evaluate("cos(pi * 45 / 180.0)");
//convert inches to feet
result = eval.Evaluate("12 [in->ft]");
//use variable
result = eval.Evaluate("answer * 10");
//add variable
eval.Variables.Add("x", 10);
result = eval.Evaluate("x * 10");

Calculator that evaluates math expressions.


Calculator.NET Features

  • Evaluate math expressions including grouping
  • Support trigonometry and other function
  • Common unit conversion of the following types
    • Length
    • Mass
    • Speed
    • Temperature
    • Time
    • Volume
  • Variable support including last answer


XML Serializable Generic Dictionary

For some reason, the generic Dictionary in .net 2.0 is not XML serializable. The following code snippet is a xml serializable generic dictionary. The dictionary is serialzable by implementing the IXmlSerializable interface.

using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

public class SerializableDictionary<TKey, TValue>
    : Dictionary<TKey, TValue>, IXmlSerializable
    #region IXmlSerializable Members
    public System.Xml.Schema.XmlSchema GetSchema()
        return null;

    public void ReadXml(System.Xml.XmlReader reader)
        XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
        XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));

        bool wasEmpty = reader.IsEmptyElement;

        if (wasEmpty)

        while (reader.NodeType != System.Xml.XmlNodeType.EndElement)

            TKey key = (TKey)keySerializer.Deserialize(reader);

            TValue value = (TValue)valueSerializer.Deserialize(reader);

            this.Add(key, value);


    public void WriteXml(System.Xml.XmlWriter writer)
        XmlSerializer keySerializer = new XmlSerializer(typeof(TKey));
        XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));

        foreach (TKey key in this.Keys)

            keySerializer.Serialize(writer, key);

            TValue value = this[key];
            valueSerializer.Serialize(writer, value);


Update: Fixed bug Justin pointed out by adding an extra reader.ReadEndElement() and by checking the IsEmptyElement property.

WilsonORMapper CodeSmith Templates

The following CodeSmith templates are to generate the WilsonORMapper mapping file and to generate the business classes that can be mapped to. These templates have the following features…

  • Converts plural table names to single tense class names
  • Cleans table names to make legal class names
  • Column name cleaning
  • Support for all relationships including many to many
  • Template based, easily changed to meet needs
  • Support for Visual Basic and C#
  • Merge support

Update: These templates are now included with CodeSmith.