Request a topic or
contact an Arke consultant

Arke Systems Blog

Useful technical and business information straight from Arke.

About the author

Author Name is someone.
E-mail me Send mail

Recent comments




The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2024

Obscure linq to sql issue - don't put 'using' at the of your partial class

Just got burned by this:


Linq breaks and exiting/restarting doesn’t fix it.  Your database project is now missing a ‘.designer.cs’ file under your .dbml file.


If you put a ‘using’ statement at the top of a partial class for a linq to sql database file (we routinely recommend making these partial classes to replace the default constructor, e.g. ) then sometimes Visual Studio deletes your .designer.cs file and so your linq just quits compiling.

Workaround is to move the using statement inside the namespace declaration, then restore your now-deleted .designer.cs file from version control or backups or else right click on the .dbml file and select "Run Custom Tool" to rebuild the file.

Timebomb, one day might kaboom:

using System.Configuration;
namespace Symmedian.SST.Data
    partial class MyLinqDataContext {

Perfectly happy and fine:

namespace Symmedian.SST.Data
    using System.Configuration;
    partial class MyLinqDataContext {

Categories: ASP.NET | LINQ
Posted by David Eison on Sunday, August 8, 2010 9:46 PM
Permalink | Comments (0) | Post RSSRSS comment feed

LinqDataSource with uniqueidentifier Primary Key

I tend to use uniqueidentifiers for my primary key columns with a default value of newid() so the database will generate a Guid for me.  I created a LinqDataSource and bound that to a DetailsView control.  I was able to insert my first row within 10 minutes of writing all this code but subsequent inserts would always throw a unique constraint exception.  After looking at the database, I saw my first row's Id was Guid.Empty so I knew that Linq was pushing this as a default value to the database instead of letting the database create a newid() for me.  It turns out the solution is very simple.  Open your DBML file, select the primary key column and change the Auto Generated Value property to true.  So far, I'm still impressed with Linq.

Categories: LINQ
Posted by Eric Stoll on Sunday, January 20, 2008 2:18 PM
Permalink | Comments (0) | Post RSSRSS comment feed