Simple CRUD Generator for C#

Martin picture Martin · Mar 23, 2009 · Viewed 40.1k times · Source

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.

Answer

John Rasch picture John Rasch · Mar 23, 2009

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