aryaxt
aryaxt

Reputation: 77596

ASP.Net - using linq to sql as my data layer?

Is it a bad idea to use linq to sql as my data-layer to retrieve data, and then populate the data into my business layer?

Am i going to be facing performance problems?

What is the most efficient way of getting data from database and populating it into my business objects?

Upvotes: 1

Views: 442

Answers (2)

Albin Sunnanbo
Albin Sunnanbo

Reputation: 47038

If you don't do anything stupid LINQ2SQL won't give you big performance problems. There is a small overhead using LINQ2SQL but that is quite small.

The most efficient way would be to select straight into your business objects in the select part.

var myResult = from product in context.Products
               where product.StockQty > 10
               select new MyBusinessProduct
               {
                   Name = product.Name,
                   Category = product.Category,
                   etc = product.etc, //...
               }

Often you can use your LINQ-objects as your business objects, you can decorate them with your business methods in a partial class and also implement the partial methods on the LINQ classes to implement validation rules.

Upvotes: 2

saille
saille

Reputation: 9181

Linq to Sql will give you good enough performance for all but the most demanding applications. If you are only ever considering using a SQL Server database, Linq to SQL is a very productive ORM to work with, and it "just works".

I used to use Linq to SQL on all .NET apps I developed on SQL Server. Then I discovered the simplicity and elegance of Entity Framework (4.1) and the Code First approach. This approach works nicely with Domain Driven Design, while allowing you to write business objects without writing any persistance code at all, by means of a convention based approach. Worth thinking about.

Upvotes: 3

Related Questions