Linq To Entities with a SQL Compact Database

A while ago I wrote this (Dutch) article on how to perform LINQ to SQL for your SQL Compact databases, since Visual Studio did not understand this, we had to do it manually, as described in the article just mentioned.

But since the release of .NET Framework 3.5 SP1, and the therein included ADO.NET Entity Framework, it is now possible to generate a model out of a SQL Compact database!

Unfortunately this is not (yet) possible for Smart Device applications (Windows Mobile), but who knows what the future might bring!

CodeRush Express – Useful tool for C# developers in VS.NET 2K8

(I quote):

Developer Express and Microsoft are proud to announce a new version of CodeRush licensed exclusively for C# developers working in Visual Studio. The new product is called CodeRush Xpress, and it includes a fresh selection of hand-picked features taken from CodeRush and Refactor! Pro.

And I love it! It has very handy functions for refactoring your code very fast!

I recommend it for everyone!

Usefull links (both contain the downloads):

If you are interested in learning the features you can access these movies:

Dustin Campbell also presented a video on this tool, among other useful Visual Studio 2008 shortcuts  on PDC 2008, you can find it here (click below for wmv-hd download).

Visual Studio 2010 CTP on VMware Workstation 6.5

I just downloaded the Visual Studio 2010 CTP (you can get it here) (an easier way to download the CTP is described here).

When you have downloaded everything you will end op with an VHD (Virtual HardDisk) and VMC (Virtual Machine Configuration). The first one contains the actual C drive of the VM, and the VMC some (default) configuration.

These files are useless in VMware, because you can’t load the VMC, nor can you use the VHD.

But you can convert the VHD (the hard disk) to a VMware-readable format.

These are the steps:

  1. Download WinImage trial here (choose your flavor).
  2. Install/extract (depending on your flavor).
  3. Open the VHD with WinImage: winimage
  4. Open your VHD (you might need to change the filter).
  5. Select Dynamically expanding disk: winimage-dyn
  6. Choose where to save your file.
  7. Now create a new VM in VMware, a Server 2008. And when it asks to create a new Hard Drive you select: Use an Existing Virtual Disk, and point it to your newly created vmdk.

Good luck!

Problems? Leave a comment :)

Microsoft Tech·Ed EMEA 2008 – Developer (2)

I would like to clarify a previous post of mine.

As stated there I will be attending Microsoft Tech·Ed EMEA 2008 – Developer in Barcelona the 10th until the 14th of November this year.

There is so much to tell about this, it will be a week PACKED with programming, no silly lessons like school, but information on a decent level.

I already made my agenda for the week (it can change though), in order for them to know how many places they must reserve for each seminar.

I mainly chose WPF and Silverlight, and User Interface. Because that is what I like, the interaction between the program and the user.

Databinding and LINQ is also very interesting, and I will be attending a seminar about that subject.

More information will follow.

SQL Server Management Studio Express 2005 Security Error (29506)

Should you ever want to install SQL Server Management Studio Express 2005 you MUST run it as Administrator.

When you try to install it on Vista (by double clicking the .exe) it extracts the files to a temp folder.

Then it launches the setup, asking you some questions. After that UAC asks you to gain Administrative access.

No problem so far, but at the end the installer notifies you of error number 29506, it cannot modify the security properties.

Solution is described here, run the installer as Administrator from cmd.

Outlook SendTo Extended: Tooltje voor Outlook

Ik heb de afgelopen 2 dagen aan een klein tooltje gewerkt om wat tekortkomingen van de normale SendTo Email Recipient weg te werken.

De reden dat de titel begint met Outlook is dat het alleen met de volledige Outlook werkt, en dan heb ik het nog niet (NOG NIET! Dat komt nog) met een versie < Office 12 (Office 2007) heb getest.

Als je de installatie uitvoert nestelt het zich in de Send To map (Kopiëren naar in een Nederlandse Windows).

En dan kan je dat gewoon op een map doen, en hij zal alle bestanden in die map kopieren naar een nieuwe mail (recursive, dus gij opent alle onderliggende mappen, en daar in ook weer alle onderliggende mappen…).

Ook maakt hij gewoon een HTML emailtje aan, ipv een stom tekst emailtje.

Ook vraagt hij niet om foto’s te verkleinen, want met het huidig internet is dat echt niet nodig.

Hieronder vind je de code (meer is het niet, buiten wat resources), het project vind je hier (rar), en de gecompileerde installer vind je hier:

using System;
using System.Collections.Generic;
using System.IO;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace OutlookSendToExtended
{
	///

	/// This class creates the mail, adds the files,
	/// and provides a function to display the emailwindow
	///
	/// Main method defined below
	/// 

	class OutlookSendToExtendedMain
	{
		#region Private vars

		///

		/// Holder for the Application entity
		/// 

		private Outlook.Application outlook;

		///

		/// Holder for the mail entity
		/// 

		private Outlook.MailItem mailItem;

		#endregion

		#region Constructor(s)

		///

		/// Constructor
		/// 

		///
array of files/folders
		public OutlookSendToExtendedMain(string[] args)
		{
			//create a new application
			this.outlook = new Outlook.Application();

			//create new emailitem
			this.mailItem = (Outlook.MailItem)outlook.CreateItem(Outlook.OlItemType.olMailItem);

			//loop over the fixed args
			foreach (string fixedArg in this.FixArgs(args))
			{
				//add the attachment
				mailItem.Attachments.Add(fixedArg, Outlook.OlAttachmentType.olOLE, 1, fixedArg);
			}

			//to be implemented
			//mailItem.SendUsingAccount
		}

		#endregion

		#region Methods

		///

		/// Enumerates over the args, expanding the folders in it
		/// 

		///
array of files/folders
		/// array of files
		private string[] FixArgs(string[] args)
		{
			List fixedArgs = new List();

			//loop
			foreach (string arg in args)
			{
				//if it is a directory
				if (Directory.Exists(arg))
				{
					try
					{
						//join the dirs and files
						List listOfAll = new List();

						listOfAll.AddRange(Directory.GetFiles(arg));
						listOfAll.AddRange(Directory.GetDirectories(arg));

						//recursive call
						fixedArgs.AddRange(this.FixArgs(listOfAll.ToArray()));
					}
					catch (Exception)
					{
						//to much exceptions to catch, catch the base.
						//what can we do? maybe talk to user.
						//thinking about this
					}
				}
				else
				{
					//it is a file, add it
					fixedArgs.Add(arg);
				}
			}

			//return the array
			return fixedArgs.ToArray();
		}

		public void DisplayEmail()
		{
			//display the email
			this.mailItem.Display(false);
		}

		#endregion

		#region Static methods

		///

		/// Entrypoint
		/// 

		///
array of files/folders to be attached
		static void Main(string[] args)
		{
			if (args.Length != 0)
				(new OutlookSendToExtendedMain(args)).DisplayEmail();

			return;
		}

		#endregion
	}
}

Even een toelichting bij de Setup: er is een PostBuildEvent gedefinieerd, die wat doet met WiRunSQL.vbs (tooltje om de database van een MSI aan te passen).

Hij voegt DISABLEADVTSHORTCUTS toe met value 1 in de Property tabel.

Waarom? Omdat ik een shortcut maak in de SendTo folder, en aangezien Advertised Shortcuts daar niet werken, moeten we dit afzetten. Dit is de enige manier hiervoor, Visual Studio bied hier geen interface voor aan.

Meer info over Advertised shortcuts vind je hier.

Commentaar? Betere manieren? Laat het me weten bij de comments :)

LINQ to SQL voor SQL Compact Edition

Als je een project maakt, en je wilt een kleinere database hebben in de plaats van een MSSQL database (mdf) kan je altijd overwegen een sdf (Compact edition).

Helaas kan je niet standaard LINQ to SQL klassen gebruiken dan (dbml).

Daarvoor kan je wel dit tooltje gebruiken, en de klassen genereren.
linq to sql

Hier volgt wat je in de verschillende textboxen moet invullen, kan je even gemakkelijk copy/pasten.

Title: Make &Linq classes for Database
Command: %vsspv_windows_sdk_dir%\bin\SqlMetal.exe
Arguments: $(ItemPath) /dbml:DataClasses$(ItemFileName).dbml /pluralize /context:DataContext$(ItemFileName)
InitialDirectory: $(ItemDir)

Dan ga je in je project op een .sdf staan, doe je tools > beneden ‘Make Linq classes for Database’, en dan doe je rechtermuisknop op je project > add extisting item > (alle files laten weergeven) > dubbelklik op de dbml.

That’s it, nu kan je eender waar in je project dit doen:

DataContextFuel dataContextFuel = new DataContextFuel(DataLayer.Properties.Settings.Default.FuelConnectionString);

Natuurlijk wel aanpassen voor jouw context he :)

Chrome compileren: WindowsSDKVer.exe crash?

Wil je ooit Google Chrome compileren volgens deze guide: hou dan rekening met de volgende (oplosbare) issues:

Als je de Windows SDK installeert, dan zorgt ie ervoor dat je geen Intellisense hebt in WPF.

En een 2de, (en dan belangrijk voor Google Chrome te compileren): WindowsSDKVer.exe geeft niets weer (op 64-bit, op 32-bit crasht ‘m zultschijnt).

Oplossing:

Repair even de installatie van Visual Studio vanuit Configuratiescherm.

SQL Server Express 2008: MDF in Visual Studio error

Er is een bug:

Als je op een machine met Vista 64-bit Visual Studio 2008 met SQL Server 2008 Express wilt gebruiken, kan je niet service based databases openen / toevoegen aan een project.

Link naar het bugreport.

Voor de rest ging de upgrade smooth: detachen van de databases, SQL Server 2005 removen, en SQL Server 2008 installeren. Jammer van deze bug, en nog irritanter: sdf (compact database) ondersteund geen LINQ, ik zit dus vast aan mdf.

Ik ga dus terug naar SQL Server 2005.

C#: WPF acceptbutton equivalent Part II

Naar aanleiding van het commentaar van whoami op mijn vorige blogpost ben ik er verder gaan kijken naar het behavior van Button.IsDefault.

Ik heb de volgende testcase gemaakt:


	
		
			
			
		
		
		
	

En de volgende code backend:

using System.Windows;

namespace TestCase
{
	///

	/// Interaction logic for Test.xaml
	/// 

	public partial class Test : Window
	{
		public Test()
		{
			InitializeComponent();
		}

		private void button_Click(object sender, RoutedEventArgs e)
		{
			MessageBox.Show(sender.ToString());
		}
	}
}

Als je dit start zal je zien dat beide knoppen zijn gefocust.

Duw je dan op enter wordt de eerste knop gefocust (er wordt geen knop getriggert), en als je daarna nogmaals op enter duwt wordt er op de eerste knop getriggerd.

Gek behavior dus.