简体   繁体   English

带有ASP.NET的动态N层

[英]Dynamic N-Layer with ASP.NET

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. 我正在尝试构建一个Web应用程序,使管理员可以通过C#与数据库对话,并添加新的表和列以满足他的要求(这是一个非常简单的数据库工作室),但我不是在尝试创建一些意大利面应用程序。

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). 1-业务对象或实体(类,即对象和属性)。 2- The Data access layer (some simple methods that connects to the database and add, update, delete retrieve items (objects)). 2-数据访问层(一些简单的方法可以连接到数据库并添加,更新,删除检索项目(对象))。

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 当您构建N层应用程序时,首先从数据库架构和实现入手,并且很容易以编程方式进行操作,然后开始构建DAL类(添加,编辑等,换句话说就是CRUD操作),并形成此数据库。

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 我想做的是允许网络管理员选择通过我的应用程序添加新表,然后-动态地-该应用程序将表名和列作为参数并创建新类并在其中定义将要实现的CRUD方法。 SQL CRUD操作

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 然后它还将动态创建类,并在其中定义变量,属性和方法以调用和使用DAL方法..所有这些都基于表,列名

NOTE : All this happens on the run-time! 注意:所有这些都在运行时发生!

You might want to look into ASP.Net Dynamic Data . 您可能需要研究ASP.Net动态数据 It's a RAD tool which very easily gives you CRUD functionality for your entities and more. 这是一个RAD工具,可以非常轻松地为您的实体提供CRUD功能。 Check it out. 看看这个。

First, any man trying to create MS Access is doomed to recreate MS Access. 首先,任何试图创建MS Access的人都注定要重新创建MS Access。 Badly. 不好

You are better off using ASP.NET Dynamic Data (as suggested) or ASP.NET MVC Scaffolding . 您最好使用ASP.NET动态数据(如建议的那样)或ASP.NET MVC支架 But runtime-generated playforms that actually make decent applications are really pipe dreams. 但是实际上由运行时生成的游戏形式构成了不错的应用程序,这真是梦pipe以求的事情。 You will need developer time to do anything complex. 您将需要开发人员时间来完成复杂的事情。 Or well. 好吧

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. 今天,我正在挖掘有关MSDN的一些信息,就像我猜到的那样,MS CRM实体模型基于元数据工作。 So basically whatever a CRM developer is working against is just metadata, they are not real objects as such. 因此,基本上,CRM开发人员所针对的只是元数据,它们本身并不是真正的对象。 Following is the MSDN link. 以下是MSDN链接。

Extend MS CRM Metadata and here is the MS CRM 4.0 SDK . 扩展MS CRM元数据 ,这里是MS CRM 4.0 SDK

I hope this should get you started. 希望这可以帮助您入门。

Update: Recently hit upon Visual Studio LightSwitch . 更新:最近击中了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. 一个UI,它将从DB中获取表信息,然后创建所有CRUD屏幕。 VS LightSwitch is in its Beta1 and has quite a lot of potential. VS LightSwitch处于Beta1状态,具有很大的潜力。 Should be a nice starting point. 应该是一个不错的起点。

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. 因为BLL和n层背后的想法是您非常了解数据模型,并且可以创建一个静态类模型来表示您的数据模型。

If your data model is dynamic, and changing, then you cannot create a static BLL (which is what a BLL is). 如果您的数据模型是动态的并且不断变化,那么您将无法创建静态BLL(BLL是静态BLL)。 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. 尽管可以在运行时动态生成类,但这可能不是您要采用的方法,因为即使您设法使BLL适应动态数据库。.调用BLL的代码也一无所知它,因此它将永远不会被调用。

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. 您将必须使用低级ADO调用从头开始设计它,而不是依靠ORM或任何自动化方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM