views:

399

answers:

6

Given a stored procedure, is there a way to auto generate a Data access layer? I understand that this can be done using Codesmith by creating cs templates, but was wondering if there's a free/paid solution out there.

The plan is for the architecture to have:

ASP.NET code behind -> Business Layer -> Data Access layer -> Stored Procedure.

The BL layer acts as a pass through to the DAL and can be auto generated as well.

Any tips/advice is really appreciated!

+2  A: 

Just use Entity Framework:
http://msdn.microsoft.com/en-us/library/bb399203.aspx

Joel Martinez
A: 

Linq2SQL or SubSonic both work well for this purpose.

Edit: Linq2Sql is supposedly "dead", but it's still quite useful in its current form. I just wouldn't make any long term investments in it.

Chris
The statement that it is dead was correct about 6 months ago. However the team that is working on EF is also working on L2S and L2S will have many new features added to it in the .NET 4.0 release.
Andrew Siemer
@Andrew Do you have a source for that statement?
Michael Maddox
@ Michael http://damieng.com/blog/2009/06/01/linq-to-sql-changes-in-net-40
Amr ElGarhy
@Amr That blog post doesn't say anything about LinqToSql having significantly more resources applied for making significant new features.
Michael Maddox
To the person who downvoted, any reason why? Seemed like a rather innocent comment to me..
Chris
@Chris, I don't downvote, but anyone who is a fan of LinqToSql has a reason to downvote your answer. You could improve your answer by explaining why you think your choices are better than other options.
Michael Maddox
One bad thing about SubSonic, it doesn't work in a medium trust enviroment very well since it's using reflection when it's doing some of it's dynamic quering.
Chris
+1  A: 

I don't yet suggest that you use Entity Framework as it still has a lot of quirks. When .NET 4.0 is officially released you will then have Entity Framework 4.0. With that release I will probably abandon NHibernate and LINQ to SQL (both have very different roles) and just use EF as it has both the ease of use of LINQ to SQL and the flexibility of NH.

For now I suggest that you use LINQ to SQL as it is very easy to get up and running and most of the time it just works!

Andrew Siemer
Given that the plan to release this project is end of first quarter of 2010 and given that this will be a framework for a rather large app, do you suggest I grab a copy of VS 2010 beta and .NET framework and use EF?
NHibernate supports Linq and has for quite a while. Every ORM has "quirks".
Michael Maddox
@OP Given that VS2010 is currently slated for a March 2010 release and that date may slip, I would not recommend taking on that dependency.
Michael Maddox
As I stated...wait for official release! LINQ to SQL or LINQ to NHibernate...Fluent NHibernate..etc.
Andrew Siemer
A: 

Another vote for Entity framework, though this will depend on the underlying table structure, not a stored procedure. I am not aware of a way to allow Entity Framework to determine the class structure based on stored proc output.

I've determined that our best approach is to manually code our classes and CRUD stored procedures. Many will argue with that solution, but in my experience using any sort of ORM framework results in less-than-optimal SQL that is limited, especially considering the power of using stored procedures that the framework will block.

Cliche's are there for a reason: if you want it done right, do it yourself. The more 3rd party components you introduce into your application, the more problems you're asking to solve that aren't under your direct control. I hate to subscribe to the Not-Invented-Here syndrome, but this is one case where I believe it is valid.

David Lively
Which ORMs have you tried that have not meet your needs? Entity Framework is hardly known for it's ability to generate performant SQL.
Michael Maddox
A: 

Check this list of most famous ORM tools ".Net"

Amr ElGarhy
Of the ones in the list, which one do you recommend?
I recommend, linqtosql, llbl, subsonic.
Amr ElGarhy
+1  A: 

Entity Framework in its current form is a non-starter for stored procedures. There's simply too much manual work that has to be done to get each stored procedure to work. I can't speak for .net 4 Entity Framework, though.

LINQ to SQL is very stored-proc friendly. Run SQLMETAL with the /procs option to have it autogenerate your DAL.

Two constraints, though:

  1. LINQ to SQL will not run stored procs that use dynamic SQL.
  2. LINQ to SQL also will not run stored procs that return data from temporary tables.

The obvious first reason is that LINQ to SQL can't generate the necessary metadata for these sprocs, but dynamic SQL in stored procs is bad practice anyway.

Cylon Cat
Of the ORMs available, LinqToSql has some of the best support for stored procedures. That said, LinqToSql is a pretty feature poor ORM and I wouldn't recommend it for the majority of projects given the superior alternatives that are freely available. It's also interesting that you recommend SQLMetal when that isn't strictly required.
Michael Maddox