Archive for October, 2007

Experimental LINQ to SQL template

June 25th 2008 • .NET, Microsoft (, , , ) • 2,335 views • 4 responses

A newer version of this LINQ to SQL template is available.

While SQL Metal does a good job of turning your SQL schema into a set of classes for you it doesn’t let you customize the code generation process.

Usefully there is now a templating system built into Visual Studio 2008 called Text Templates (T4 for short).

Here is a short (369 line) experimental proof-of-concept T4 template I wrote last night that will generate a data context and associated entity classes as a starting point similar to that produced by SqlMetal.

Download of this old version no longer available, see the newer article!

Once downloaded unzip and drop the DataContext.cs.tt into your project and edit line 17 to set the connection string. You can also edit lines 18 and 19 to set the namespace and class name. The lightweight wrappers around database, table and column can be found at the end of the file – they simply wrap the SQL Server Information_Schema views as briefly as possible.

Within seconds Visual Studio should have created a code-behind file for the DataContext named DataContext.cs.cs with your generated code ready to use :) If you don’t like the way the template generates your context you can change it :)

There are limitations with this experimental proof-of-concept including: 

  • Processes all and only tables in the database (no views or SP’s)
  • Foreign-key relationships are not implemented
  • Column attributes for IsDbGenerated, UpdateCheck and AutoSync not implemented
  • C# only (sorry Julie)
  • Plural and singular naming rules are incomplete
  • Can’t modify schema as you could with a designer stage
To learn more about T4: 

[)amien

DamienG.com rises from the ashes

June 2nd 2008 • Internet () • 450 views • 2 responses

On Saturday an explosion at ISP ThePlanet took this site offline and it remained like that for 48 hours whilst power and structure were restored to the 4,000+ affected servers.

It’s unfortunate it happened when the site got some DotNetKicks and StumbleUpon love for Envy Code R but at least this isn’t a commercial venture losing money to such an incident – if it was I’d have a warm standby somewhere else – something many of ThePlanet’s commercial customers didn’t.

If downloads and images aren’t working for you then you’ll need to clear your DNS cache which may help the problem depending on the cache at your forwarder.

Windows ipconfig /flushdns
OS X Tiger lookupd -flushcache 
OS X Leopard dscacheutil -flushdns

This has skewed the FeedBurner stats so if you’re new here and take that as any measure of popularity it was 500+ last week :)

[)amien