views:

5115

answers:

10

Hello all,

I am looking for a simple CRUD (or DAL) Generator for C#. I don't want anything heavyweight since I only have a couple of tables in a SQL Server 2008 database.

Any suggestions? I know .netTiers, but it is way too much for what I need.

Thanks!

UPDATE: I tried LINQ to SQL and it doesn't work well for my needs.

+1  A: 

LINQ To SQL is easy and it's built into .NET 3.5 SP1.

Paul Mendoza
It is what I have been trying to use for a couple of days and it is a nightmare. Espacially that I have M:M relation...
Martin
+2  A: 

MyGeneration has some pretty good CRUD SP generation templates

MrTelly
+2  A: 

What about using a DataSet created using the DataSet designer. I remember back in the Old Days (.NET 1.0 and 1.1), we would drag a DataAdapter onto the design surface, specify the Select query, and the Insert, Update and Delete queries would be created for us, based on the Select query.

John Saunders
+1  A: 

The Visual Studio wizards will create a simple CRUD app for you.

Drag a datagrid on your form, click the connection property and follow the wizards from there.

Not best practices but is simple and works...

jms
+7  A: 

I have used SubSonic on past projects, it's lightweight and easy to use.

They offer a simple tutorial video and it should take no more than 10 minutes to get it completely setup. I recommend watching the second half of the video that deals with Web Application Projects because it shows you how to create a customized Visual Studio button that creates the DAL for you whenever you click on it instead of using a custom build-provider as they suggest in first half of the video.

It offers several ways to access your data, Active Record, generating typed stored-procedures and views, or a query language that you can use.

After using it, I have found a few quirks:

  • If you use a generated stored-procedure that does not have a parameter, it will throw a NullReferenceException. A workaround is to create a dummy parameter that isn't used in the procedure
  • The DeepSave() function does not work in the current 2.1 version, you'll have to individually save data from joined tables
  • When you use a coditional (e.g. Where(Tag.Columns.TagName).IsEqualTo("subjective"), make sure you use the string value Tag.Columns.TagName to reference the column - otherwise an exception will be thrown if you try to use the Column.Schema
John Rasch
Subsonic is probably the lightest DAL maker that I have found so far. Everything else has become far too bloated. Try version 2.1, which now has an installer.
hectorsosajr
+1  A: 

Just in case money isn't a big concern, I've had great success with templates in CodeSmith.

There are plenty of sample templates out there for CRUD operations and it'll read directly from your database.

Damovisa
I agree, I use code smith for lightweight stuff, it is also easy to write your own templates if you are trying to integrate into an existing project which can be really handy.
Element
+3  A: 

Visual Studio comes with a code generator that hardly anyone knows about called T4.

You should be able to use it relatively easily to create CRUD templates.

EDIT

And here's an example how: http://www.olegsych.com/2008/01/how-to-use-t4-to-generate-crud-stored-procedures/

Giovanni Galbo
Wow, new to me - thanks!
Damovisa
+1  A: 

Have you tried the Dynamic Data Web Application (uses LINQ to SQL) or the Dynamic Data Entities Web Application (uses Entity Framework).

MSDN: Walkthrough: Creating a New ASP.NET Dynamic Data Web Site Using Scaffolding

bendewey
+1  A: 

Take a look at Codesmith. The 2.6 version is free and the later versions are for purchase.

asp316
A: 

Check out LLBLGen Pro, I swear by it. It is not free, but not expensive. You can get up and running (writing code) within an hour, and the templates it comes with generate code that can do basically anything you would want. It is so nice (and productive) to not even have to think about database interface code anymore.

tbone