LINQ to SQL and stored procedures, my quest continues - Craig Nicholson

Craig Nicholson

My blog has moved to http://craign.net/.

News

My blog has moved to http://craign.net/.


AfrigatorI shmaak SA Blogs, sorted with Amatomu.comSign the petition for Xbox LIVE in South Africa. Locations of visitors to this page

Communities

Development Blogs

Development Tools

General Tools

Personal

LINQ to SQL and stored procedures, my quest continues

Recently I posted some reservations on LINQ and in particular LINQ to SQL and the usage of stored procedures. After numerous comments from respected community members I have furthered my quest on the subject and found a very interesting blog entry by Mark Seemann where he shares his thoughts on how LINQ to SQL will impact database development best practices. I feel that he shares my thoughts on the subject and he raises some interesting comments.

I am a firm believer in the current database development best practice of providing a stored procedure interface to a database to provide a layer of abstraction, increase maintainability and allow for performance improvement through database query optimisation and tweaking. Sometimes this includes blurring the ideals of having the business logic implemented completely outside of the database in the hypothetical business logic layer or object workspace.

If the business logic is to truely exist in the business logic layer then LINQ to SQL might really be the future and maybe some of the database development best practices should be tossed out of the window in favour of a strict database schema with all business logic constraints enforced by the application developer. From my experience this just doesn't work in the long run. Sure an application developer can use an ORM tool already to do a lot of what LINQ to SQL does and what do you get, a very loose database schema that leaves a lot to be desired from a data integrity and performance perspective. Why should a database query be designed by the application developer doing the business logic layer? Surely a database guru should be featured somewhere in the process. At least with stored procedures the application developer could define the interface and the database guru could optimise it thereafter.

So maybe a hybrid approach is the way forward. Yes LINQ to SQL does provide support for calling stored procedures and I think that it has its benefits, but from my reading so far I just don't see myself using delayed insert or update stored procedure execution to update business entities involving complex business inter-dependencies.

So the questions that remain to be answered, will a pure LINQ to SQL solution have an impact on performance? Will it suffer in the long run?

Another interesting question that comes to mind is that of SQL Server Reporting Services (SSRS). If the idea is to push the business logic into code then I suppose the only feasible way of exposing it would be through Service-Oriented Architecture (SOA). So are we going to see extensions to SSRS to talk to web services and Windows Communication Foundation (WCF) instead of stored procedures and T-SQL statements?

Update: I have subsquently found that SSRS has the ability to call web services using its XML data extension but it looks really tedious.

Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# March 22, 2007 11:48 PM

Jeremy Miller said:

Using an O/R Mapper in no way abrogates your responsibility to apply the same rigorous referential integrity checks in the database.  Actually, it's quite the opposite.  O/R Mappers generally cannot handle orphan and ghost records.

I don't really see how using an O/R Mapper is going to leave you with a poorly designed schema either.  The work and process of designing the database schema doesn't really change.  Besides, all Linq to SQL does is generate classes directly off of your schema anyway.

# March 23, 2007 11:09 AM

jc said:

In my experience, writing a purely stored procedure abstraction to the database model is a hugely inefficient approach to web application development. That hasn't stopped me from doing it as I've used this approach in every .NET project I've worked on, but it creates such a huge detachment for the developer that productivity is extremely diminished.

Personally I think it would make sense to use the fastest, most productive approach (Linq statements) and use stored procedures to optimize the most inefficient queries (based on real world measurement). Prematurely optimizing by requiring a huge stored procedure abstraction I think is a mostly wasted effort.

# March 23, 2007 5:24 PM

DaRage said:

man you're some development dinosaur with layers and dba writing stored procs. use linq and get rid of all these layers:)

# March 23, 2007 8:19 PM

Lucio said:

Could you explain these in more detail?

' ORM tool (...) and what do you get, a very loose database schema that leaves a lot to be desired from a data integrity and performance perspective.'

What data integrity and performance disappointments have you had with an ORM tool?

'Why should a database query be designed by the application developer doing the business logic layer?'

Why shouldn't it?

'Surely a database guru should be featured somewhere in the process.'

Why so surely?

# March 23, 2007 8:26 PM

Ian Cooper said:

eBay does not use stored procedures - to allow them to scale - instead they use an ORM tool:

http://iancooper.spaces.live.com/blog/cns!844BD2811F9ABE9C!337.entry

# March 24, 2007 10:15 AM