Dynamic N-Layer with ASP.NET

701 views Asked by At

I'm trying to build a web application that let the administrator talk to the database through C# and add new tables and columns to fit his requirements (sort of a very simple database studio) but I'm not trying to just create some spaghetti application.

So I'm trying to figure out how to let those things dynamically (automatically) when he creates a table and use the table to build them :

1- The business objects or entities (the classes, it's objects and properties). 2- The Data access layer (some simple methods that connects to the database and add, update, delete retrieve items (objects)).

Is this possible ? any pointers on how to achieve it ?

EDIT

just opened your link!! .. it's talking about the data bound controls and stuff! .. my question is way more advanced than that!. when you build an N-Layered application you start with the database schema and implementation and it's easy to do programtically then you start building the DAL classes which (add, edit, etc in other words the CRUD operations) in and form this database

what I want to do is to allow the web administrator to choose add the new table through my application and then -dynamically- the application would take the tables names and columns as parameters and create new classes and define within them the CRUD methods that will implement the SQL CRUD operations

then it would also create dynamically the classes and define within them the variables, properties and methods to call and use the DAL methods .. all this based on the table, column names

NOTE : All this happens on the run-time!

4

There are 4 answers

1
Pradeep On BEST ANSWER

Sometime back I had also asked similar question on SO. I got only one reply.

Today I was digging some information on MSDN and as I had guessed it, MS CRM entity model works based on metadata. So basically whatever a CRM developer is working against is just metadata, they are not real objects as such. Following is the MSDN link.

Extend MS CRM Metadata and here is the MS CRM 4.0 SDK.

I hope this should get you started.

Update: Recently hit upon Visual Studio LightSwitch. I think this is what we wanted to build. A UI which will pick up table information from DB and then create all CRUD screens. VS LightSwitch is in its Beta1 and has quite a lot of potential. Should be a nice starting point.

1
Wyatt Barnett On

First, any man trying to create MS Access is doomed to recreate MS Access. Badly.

You are better off using ASP.NET Dynamic Data (as suggested) or ASP.NET MVC Scaffolding. But runtime-generated playforms that actually make decent applications are really pipe dreams. You will need developer time to do anything complex. Or well.

5
Erik Funkenbusch On

What you are asking is non-sense. Why? Because the idea behind BLL and n-tier is that you know your data model well, and can create a static class model to represent your data model.

If your data model is dynamic, and changing, then you cannot create a static BLL (which is what a BLL is). What you will have to do dynamically build your queries at run-time. This is not something that any of the traditional methods are designed to handle, so you must do everything yourself.

While it's possible to dynamically generate classes at run-time, this is probably not the approach you want to take, because even if you manage to make your BLL adapt to your dynamic database.. the code that calls the BLL will not know anything about it, thus it will never get called.

This is not a problem you will solve overnight, or by copying any existing solution. You will have to design it from scratch, using low level ADO calls rather than relying on ORM's or any automation.

1
Bala R On

You might want to look into ASP.Net Dynamic Data. It's a RAD tool which very easily gives you CRUD functionality for your entities and more. Check it out.