Home » none » Is LINQ Multi Layered?

Is LINQ Multi Layered?

Several weeks ago, we discussed the point of Multi-Layered Architectures.  We discussed what a multi-layered architecture looks like, and the problems it solves.

Today, what I want to examine is the question, “Is the LINQ model we’ve been looking at since then really multi-layered?”

So, the first thing we should examine is obviously, does it look multi layered on the surface?  I guess that really depends on how you look at LINQ.  My first tendancy was to view the LINQ to SQL classes and the extension points as two different layers.


But, on closer inspection, I think what we really have is this:


To a large extent, it is the attributes of the LINQ 2 SQL classes that are controlling the access to the database.  The methods are the conduit between the presentation layer and the data access layer.

So, yes, it looks multi-layered.

So, does it meet the other criteria we setup?  Does this model solve all of the problems?

  • Does it keep business logic out of the presentation layer?

Well, it almost does this?  If you ask me, Microsoft has a pretty funky implementation for using a SELECT stored procedure that pretty well forces the call into the presentation layer.  Further, you could add filtering code in the event handler that would force more BLL code into the presentation layer.  The SELECT method would have been better implemented like the INSERT/UPDATE/DELETE methods in the LINQ 2 SQL classes.

  • Does the DAL only have code in it that gets data out of the database?

Yes, since Microsoft is doing all of this for us via the attributes, this is pretty well separated.

  • Does the BLL allow us to validate our data on the way down to the database?

Yes, this has been well implemented via the extension points.

  • Does the BLL allow us to translate our data as we move it from the DAL to the View and back again.

Yes, again, this is allowed by using extension points.

  • Can we swap out the presentation layer?

Yes, we should be able to do this without much trouble.

  • Can we swap out the DAL?

No, LINQ 2 SQL is pretty well tied to MS-SQL.

  • Can we place each of the layers on different computers?

No, but this does not mean it is not multi-layered.  It only means that we can’t use it in a mult-tiered implementation.  The ideal would be for it to do both.

So, we have one place in LINQ 2 SQL where it fails true multi-layered capabilities and another nice to have that we’ve lost. 

Does it matter?

If all you are building is web sites that use MS-SQL for the database, it probably doesn’t matter.  While I would not call this a multi-layered architecture, it is a functional architecture for building web applications that don’t have a completely unorganized mismatch of code that no one would know how to maintain if they were not the ones who had written it.

However, if you are planning to use the same code base for web applications and other applications, like windows forms, or you need this to work with multiple databases, you may need to provide a few tweaks to this model so that it will work for you, instead of against you.

Like this Article? Subscribe to get every article sent to your email.

Related Post

  • Computed Columns Using LINQ to SQL ClassesComputed Columns Using LINQ to SQL Classes Last week we looked at the extension points Microsoft has wired into the LINQ to SQL classes and how they can be used to achieve some of the capabilities of the Business Logic Layer (BLL) […]
  • Using StoredProcedures with LINQ 2 SQL ClassesUsing StoredProcedures with LINQ 2 SQL Classes While it is true that LINQ will allow you to write all of your data access in .NET without writing a line of SQL, many organizations have already determined that using stored procedures to […]
  • Partial Classes and Partial MethodsPartial Classes and Partial Methods In order to understand how Microsoft intends LINQ to be used in a multi layered architecture, we first need to take a look at partial classes, which have been around since .NET 2.0, and […]
  • Multi-layer LINQ via Extension PointsMulti-layer LINQ via Extension Points As promised a few days ago, I will be covering multi-layered architecture as it relates to LINQ. The first thing we need to evaluate is how Microsoft intended multi-layered architecture […]
  • Document/View All Over Again…Document/View All Over Again… Back when we programmed in C++ using the Microsoft Foundation Classes (MFC) we had a framework that we programmed in called "Document/View." The question I keep asking myself as I think […]

About Dave Bush

Dave Bush is a Full Stack ASP.NET developer. His commitment to quality through test driven development, vast knowledge of C#, HTML, CSS and JavaScript as well as his ability to mentor younger programmers and his passion for Agile/Scrum as defined by the Agile Manifesto and the Scrum Alliance will certainly be an asset to your organization.