Two LINQ to SQL Myths

LINQ to SQL requires you to start with a database schema.

Not true – you can start with code and create mappings later. In fact, you can write plain-old CLR object like this:

class Movie
{
    
public int ID { get; set; }
    
public string Title { get; set; }
    
public DateTime ReleaseDate { get; set; }
}

… and later either create a mapping file (full of XML like <Table> and <Column>), or decorate the class with mapping attributes (like [Table] and [Column]). You can even use the mapping to create a fresh database schema via the CreateDatabase method of the DataContext class.

LINQ to SQL requires your classes to implement INotifyPropertyChanged and use EntitySet<T> for any associated collections.

Not true, although foregoing either does come with a price. INotifyPropertyChanged allows LINQ to SQL to track changes on your objects. If you don't implement this interface LINQ to SQL can still discover changes for update scenarios, but will take snapshots of all objects, which isn't free. Likewise, EntitySet provides deferred loading and association management for one-to-one and one-to-many relationships between entities. You can build this yourself, but with EntitySet being built on top of IList<T>, you'll probably be recreating the same wheel. There is nothing about EntitySet<T> that ties the class to LINQ to SQL (other than living inside the System.Data.Linq namespace).

LINQ to SQL has limitations and it's a v1 product, but don't think of LINQ to SQL as strictly a drag and drop technology.

posted on Sunday, May 11, 2008 11:47 PM by scott

Comments

Sunday, May 11, 2008 11:02 PM by fresh

# Two LINQ to SQL Myths

Bookmarked your post over at Blog Bookmarker.com!
Monday, May 12, 2008 12:42 AM by Christopher Steen

# Link Listing - May 11, 2008

Link Listing - May 11, 2008
Monday, May 12, 2008 12:42 AM by Christopher Steen

# Link Listing - May 11, 2008

WPF Panel3D now supports transparency [Via: Josh Smith ] Code Camps CodeStock in Knoxville, TN on August...
Sunday, May 18, 2008 12:28 PM by Community Blogs

# Dispelling some urban legends about LINQ to SQL

Scott has a great post where he dispels the following two myths about using LINQ to SQL. LINQ to SQL
Sunday, May 18, 2008 4:56 PM by Chad Myers

# re: Two LINQ to SQL Myths

Are there any links with examples of people doing domain-driven design/persistence ignorance style persistence stuff with Linq2Sql?

I know Ian over at CodeBetter did some stuff like this and I haven't made it through his whole series, but it didn't impress me as something that would replace NHibernate as it was lacking several critical features.

Almost all the examples/samples I've seen of Linq2Sql are of the drag-n-drop-your-database-into-your-code ilk.
Sunday, May 18, 2008 5:35 PM by scott

# re: Two LINQ to SQL Myths

@Chad: I don't know anyone other than Ian who has graciously taken the time to write about DDD with L2S.

nHibernate is years ahead of L2S. The one advantage L2S has is its exteme simplicity (and not the drag and drop designer type). That's also one of it's big weaknesses - only basic mappings are available, only SQL Server is supported. If that's all you need its refreshingly light, and the standard LINQ operators make it easy to build repositories.
Sunday, May 18, 2008 9:02 PM by Glenn Block

# Dispelling some urban legends about LINQ to SQL

Scott has a great post where he dispels the following two myths about using LINQ to SQL. LINQ to SQL
Sunday, May 18, 2008 9:36 PM by Glenn Block

# Dispelling some urban legends about LINQ to SQL

Scott has a great post where he dispels the following two myths about using LINQ to SQL. LINQ to SQL
Sunday, May 18, 2008 9:37 PM by My Technobabble

# Dispelling some urban legends about LINQ to SQL

Scott has a great post where he dispels the following two myths about using LINQ to SQL. LINQ to SQL
Tuesday, May 20, 2008 11:57 AM by Community Blogs

# Dispelling some urban legends about LINQ to SQL

Scott has a great post where he dispels the following two myths about using LINQ to SQL. LINQ to SQL
Tuesday, May 27, 2008 6:42 PM by Jim Wooley

# re: Two LINQ to SQL Myths

Scott, I fully agree with you that LINQ to SQL does offer some benefits over the EF in terms of POCO support. Using the XML mapping is a great solution for existing classes so that you can keep the classes completely isolated to the underlying technology. We discuss this option along with the associated pluses and minues in LINQ in Action. In addition, I will be calling attention to it in my beyond the basics talk at the TechEd Tweener weekend.

The main drawback that LINQ to SQL has in relation to the Entity Framework and NHibernate is the one-to-one table mapping requirement. It doesn't allow for the richer schema mappings without using views and stored procs.
Tuesday, May 27, 2008 7:35 PM by scott

# re: Two LINQ to SQL Myths

Jim: Agreed. The mapping is a deal breaker for many scenarios, unfortunately.
Thursday, July 03, 2008 2:15 AM by LINQ in Action roller

# How does EntityRef work?