C # class from SQL database table

Moved through this:

http://www.eggheadcafe.com/articles/adonet_source_code_generator.asp

And I wonder if this decision is right, because I'm not so big a fan of creating a class for each stored procedure, or I'm using the Enterprise Library project for ASP.net 2.0.

+4
source share
4 answers

You definitely should not create a class for each stored procedure. There are a number of approaches that you can take to handle interacting with databases. You should take a good look at the main framework and decide which one is right for you. Castle Project's solution is great and relies on nHibernate ( nHibernate ). LINQ is a similar proposal from Mircrosoft ( LINQ Project ). Both of these solutions are complete ORM (Relational Object Mapping) structures and will generate dynamic SQL to store your objects in the database. Everyone also has their own quirks and you like to structure your objects in certain ways. If you do not want to control the SQL that your system uses, I definitely recommend one of these approaches.

I come from the background of the database and prefer a bit more control over my SQL. In particular, I like it when my breaks are handled by stored procedures. I find that this allows me to better manage SQL and optimize, but it helps me more securely manage database security. To take this approach into account, I recommend something like iBatis ( iBatis ). iBatis is not a complete ORM, but a simple SQL calculator. The drawback of my approach is that you need to write a lot more code (SQL), but I am not against compromise.

+6
source

Is it possible to upgrade to the 3.5 framework? if so, take a look at LINQ to SQL and Entity Framework, as this will help you with that.

If not, then as long as it generates standard code that does not link you to third-party libraries, you can certainly use it. At my workplace, we have our own generator, similar to this, and it works well, although we will move on to LINQ to SQL soon.

0
source

There are many ways to migrate a database table to a C # class; you probably want to explore a few alternatives before deciding between the one you contacted and the Entity Framework.

There is a program template called the โ€œactive recording templateโ€ that describes this particular approach: one C # class for each table, with loading and saving methods such as Customer.GetById (), Customer.Save (), etc.

For ASP.NET 2.0, check out the Castle Project ActiveRecord implementation and a third-party Visual Studio plugin tool called ActiveWriter , which lets you create class wrappers for your tables using the drag'n'drop interface.

0
source

You will need to determine at what point you need the data sets that consist of your tables, and whether you want SQL to produce them using stored procedures or if your level of business logic will process this data. As Dr8k says, nHibernate will create SQL for you, but there is a learning curve with nHibernate. ORM will control how you receive data, and depending on the level of your environment and the level of DBA support, you can solve other problems.

If you are comfortable with SQL, then there is another tool called SubSonic that will create ala Active Record wrappers for you, suggesting you can also use stored procedures. There is also a nice query tool with a smooth interface that you can use if you cannot use LINQ.

0
source

All Articles