Best Practices: 3-Tier Architecture in LINQ

I am working on a personal project (C # / ASP.NET) that will use LINQ to SQL. The solution will have (for now) a Webform project, a namespace project (business logic), and a Tests project. I am at a very early stage so far (obviously at the design stage).

Is there a paradigm for 3-tier architecture? It seems that DAL is completely useless in this case; It looks like I should execute the LINQ query directly from the business logic.

It also occurs to me that if I just leave one resident DataContext and pass it on, I only need one open connection. This will have the added benefit of making changes immediately, rather than granularly. Any thoughts on this?

I found this topic , but it seems he is painting an incomplete picture. Are there any detailed articles on this?

+5
source share
4 answers

You can think of LINQ-to-SQL as your DAL, so using it "directly from the business logic" is not necessarily bad.

http://dotnetlog.com/archive/2008/03/18/best-practice-and-effective-way-of-using-datacontext-in-linq.aspx contains some popular L2S approaches.

, , # 3, (Ambient DataContext, . ). , ; , -.

Ambient DataContext ( )

datacontext , httpcontext ( asp.net), DataContext. , . /. DataContext, . Asp.Net, - .

:

* The context is available for manipulation at any level. And quickly becomes very hard to maintain unit of work
* Portability across thread is very hard
* Unit of work pattern is not transparent enough
+4

Domain Driven Design.

Domain Driven Design (DDD) " ", , . ( ), -. .
- , ( ); - . , .

Linq To SQL , . , , (/) (//). ? → , . (, , , ), / . ( DataContext). DataContext .

( DDD, ).

+5

. LINQ, Linq-to-sql, , 3 , , . , , .

- ORM, linq-to-sql. DAL . , -, , -.

.

ORM - linq-to-sql . NHibernate.

+1

LINQ to SQL - DAL, API - (, DAL.GetObjectById(id)), DAL.

, , LINQ, , MSSQL, DAL.

In addition to the DataContext, it is not recommended to use a singleton template with a "single resident DataContext". The DataContext must be a single logical transaction, regardless of what this means for your application. (Paraphrase from http://weblogs.asp.net/despos/archive/2008/03/19/more-on-datacontext-in-hopefully-a-realistic-world.aspx )

0
source

All Articles