使用 ASP.NET 的动态 N 层

发布于 2024-10-19 11:34:36 字数 591 浏览 6 评论 0原文

我正在尝试构建一个 Web 应用程序,让管理员通过 C# 与数据库对话,并添加新的表和列来满足他的要求(有点像一个非常简单的数据库工作室),但我不想只是创建一些意大利面条应用程序。

因此,我试图弄清楚当他创建表并使用表来构建它们时如何让这些东西动态(自动):

1-业务对象或实体(类,它的对象和属性)。 2- 数据访问层(一些连接到数据库并添加、更新、删除检索项(对象)的简单方法)。

这可能吗?有关如何实现它的任何指示?

编辑

刚刚打开您的链接! ..它谈论的是数据绑定控件之类的东西! ..我的问题比这更高级! 当你构建一个 N 层应用程序时,你从数据库模式和实现开始,并且很容易以编程方式完成,然后你开始构建 DAL 类(添加、编辑等,换句话说 CRUD 操作)并形成

我想要的 数据库。想要做的是允许 Web 管理员选择通过我的应用程序添加新表,然后动态地应用程序将表名称和列作为参数并创建新类并在其中定义将实现 SQL 的 CRUD 方法CRUD 操作

然后它还会动态创建类并在其中定义变量、属性和方法来调用和使用 DAL 方法.. 所有这些都基于表、列名称

注意:所有这一切都发生在运行时!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

乖不如嘢 2024-10-26 11:34:36

您可能需要查看 ASP.Net 动态数据。它是一个 RAD 工具,可以轻松为您的实体等提供 CRUD 功能。一探究竟。

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.

合约呢 2024-10-26 11:34:36

不久前,我也曾问过类似问题。我只得到一个答复。

今天我在 MSDN 上挖掘了一些信息,正如我所猜测的,MS CRM 实体模型基于元数据工作。因此,基本上,CRM 开发人员所处理的一切都只是元数据,它们本身并不是真正的对象。以下是 MSDN 链接。

扩展 MS CRM 元数据,这是MS CRM 4.0 SDK

我希望这能让你开始。

更新:最近偶然发现Visual Studio LightSwitch。我认为这就是我们想要构建的。一个 UI,它将从数据库中获取表信息,然后创建所有 CRUD 屏幕。 VS LightSwitch 正处于 Beta1 阶段,具有相当大的潜力。应该是一个很好的起点。

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.

归途 2024-10-26 11:34:36

首先,任何试图创建 MS Access 的人都注定要重新创建 MS Access。糟糕的是。

您最好使用 ASP.NET 动态数据(如建议)或 ASP.NET MVC 脚手架。但是,运行时生成的游戏形式实际上可以制作出像样的应用程序,这确实是白日梦。您将需要开发人员时间来完成任何复杂的事情。或者好吧。

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.

东风软 2024-10-26 11:34:36

你所问的是无意义的。为什么?因为 BLL 和 n 层背后的想法是您非常了解您的数据模型,并且可以创建静态类模型来表示您的数据模型。

如果您的数据模型是动态的且不断变化,那么您无法创建静态 BLL(这就是 BLL)。您必须在运行时动态构建查询。这不是任何传统方法都可以处理的事情,因此您必须自己完成所有事情。

虽然可以在运行时动态生成类,但这可能不是您想要采用的方法,因为即使您设法使 BLL 适应动态数据库..调用 BLL 的代码也不会知道任何信息它,因此它永远不会被调用。

这不是一个一夜之间就能解决的问题,也不是通过复制任何现有解决方案就能解决的。您必须使用低级 ADO 调用从头开始设计它,而不是依赖 ORM 或任何自动化。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文