LINQ to SQL and Visual C# Developer Express Data Source Connections

While I was evaluating a couple of things including LINQ to SQL (or L2S to some) for a small website I tried to look into whether it was possible to have the LINQ to SQL classes on a separate project (eg. DAL) rather than the website itself. [more]

Since Visual Web Developer Express Edition (you need 2008 for LINQ to SQL) doesn't support having more than one project inside a "solution" I downloaded the Visual C# Express Edition. Note that these are not SP1 beta versions. Haven't looked into those.

I created the C# class library project. Then opened the database explorer and tried to add a connection. You will notice though that only three types of data source available:

They are : Access Database File, SQL Server Compact 3.5 3) and SQL Server Database File.

Since the LINQ to SQL ORM Designer (visual designer for DBML) is need the database explorer to drag and drop tables, objects from then it would mean there it becomes a little problem if you're working on a SQL Server instance rather than a file. (which is common to shared hosting since most if not all doesn't support running/attaching user instances anymore)

One way to work around this however is to the detach the data file (*.mdf) from the SQL Server then add a connection to the file from the database explorer. (detach is likely needed otherwise you might encounter some file locking issues). This would create a new connection string in your app.config which involves attaching the data file. However you can edit this to point to the SQL Server instance containing your database instead without a problem. (** make sure though that you have attached it back to SQL Server).

So basically, it is still definitely possible to have a class library in Visual C# Express 2005 to have LINQ to SQL classes targetted to a SQL Server instance database rather than a database file despite not having that data source option when creating a new connection in database explorer. The limitation is simply more of a hassle in designing.

Not very convenient but you can always design/code against the data file during development and just attach that file to SQL Server and change the connection string.

There could be a way to add the SQL Server option (not the SQL
Server Database File) when adding new database explorer connections but haven't looked into that. Will be sure to
update this if I do.

Also there are a lot of discussions going on regarding discontinued support for LINQ to SQL in favor of ADO.NET Entity Framework (EF) so you might want to read a little on those first before making some decisions. Probably not a problem with small projects but then again, it doesn't hurt to be aware of the issues. It may or may not be true and I would still look into L2S definitely but knowing it was created by the C# team while EF by the data programmability team, plus EF has more features/flexibility than the other and that the ADO.NET MCTS exam prep guide has a section for EF but only a mention of LINQ (and not LINQ to SQL specifically) I'm more inclined to think EF will gain more support moving forward.


Posted

in

by

Tags: