Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple CRUD Generator for C# [closed]

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.

like image 910
Martin Avatar asked Mar 23 '09 02:03

Martin


2 Answers

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
like image 193
John Rasch Avatar answered Sep 16 '22 12:09

John Rasch


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/

like image 40
Giovanni Galbo Avatar answered Sep 19 '22 12:09

Giovanni Galbo