Månad: september 2008

Tree ways to do the samething

double sumOfAccountSaldo = 0;
Account[] accounts = new Account[] {new Account() {Saldo = 100}, new Account() {Saldo = 2300}};
//Traditional syntax
foreach (Account account in accounts)
    sumOfAccountSaldo += account.Saldo;

//Query syntax
var query = from a in accounts
                  select a.Saldo;
sumOfAccountSaldo = query.Sum();

//Lambda syntax
sumOfAccountSaldo = accounts.Sum(a => a.Saldo);

Problem compiling AJAX Control Toolkit ?

I have installed Visual Studio 2008 on tree computers lately (just for fun of course), I´ve discovered a general problem with Ajax Control Toolkit SDK. I download it from Codeplex and then try to compile the solution, every time I get this error:

"Error    1    Could not load file or assembly ‘vjslib, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. Det går inte att hitta filen.    C:\Program Files\Microsoft Visual Studio 9.0\SDK\AJAX Toolkit SDK\TemplateVSI\TemplateVSI.csproj    37    5    TemplateVSI"

Well I have a solution for this I just download and install the Visual J# Redistrebutable package from this site: http://msdn.microsoft.com/en-us/vjsharp/bb188598.aspx

Then it´s just to run the compiler, I guess this is only a problem in Visual Studio 2008.

LinqToSql about DataContext

Linq is very new so it´s not that easy to fully understand how every object is supposed to be used. What I (and others) wonder is how to use the DataContext object. I have used one static DataContext using the singleton pattern. But I found limitations with this, googling around I found a very interesting article that Dino Esposito one of the architects of Linq wrote. Here some of it you can read the whole article here:

In general, a DataContext instance is designed to last for one unit of work however your application defines that term. It is not recommended to maintain a DataContext live for more such as stored in a singleton object. DataContext should be kind of using an ADO.NET connection: you use always new DbConnection objects but reuse command text and parameters. You never keep a connection open for a long time and don’t pass it around tiers.

Dino Esposito


Visual Studio 2008 Adding User database instances with new item template

I noticed today when I try to add a new database with the SQL Server Database template in the "add item function" in Visual Studio that the SQL Server Express installation default is configured not to allow this.

You have to run this SQL script to change the configuration:

First: sp_configure ‘user instances enabled’, 1


All done now you can add new database with the template.