多租户和用户可定义表单

发布于 2024-09-26 12:04:08 字数 798 浏览 2 评论 0原文

我们正在设计新产品,其中将包括多租户。它将用 ASP.NET 和 C# 编写,并可能托管在 Windows Azure 或其他云托管解决方案上。

我们一直在研究 MVC 和其他技术,老实说,我们陷入了各种缩写词(MVC、EF、WCF 等)的泥潭。

我们的应用程序的一个特殊要求引起了头痛——用户将能够向数据库添加字段,甚至创建一个全新的模块。

因此,每个租户都会拥有一个与使用该系统的每个其他租户具有不同结构的数据库。我们设想每个租户都有自己的数据库,而不是共享数据库。

(向系统添加字段等将使用 Web 界面完成)。

一切都很好,但在为 MVC 创建数据模型时就会出现问题。根据以下链接,以编程方式修改数据模型以将字段添加到表中似乎是不可能的:

在运行时创建EDM?

这对我们来说是一个非常头疼的问题。即使我们不使用 MVC,我认为我们仍然想要创建一个数据模型(也许与 LINQ to SQL 一起使用)。

我们正在考虑建立一个包含大量字段的表,当用户想要向其表单添加字段时,我们不是在数据库中添加字段,而是在表中分配现有字段。不过,我不确定我喜欢这个主意。

当然,我们不必使用 MVC 或实体框架,但在我看来,这些是微软将引导我们未来开发的技术。

有什么想法吗?我假设我们不是世界上第一批考虑用户可定制应用程序这一想法的人。

We are designing our new product, which will include multi-tenancy. It will be written in ASP.NET and C#, and may be hosted on Windows Azure or some other Cloud hosting solution.

We’ve been looking at MVC and other technologies and, to be honest, we’re getting bogged down in various acronyms (MVC, EF, WCF etc. etc.).

A particular requirement of our application is causing a headache – the users will be able to add fields to the database, or even create a whole new module.

As a result, each tenant would have a database with a different structure to every other tenant using the system. We envisage that every tenant will have their own database, rather than sharing a database.

(Adding fields etc. to the system will be accomplished using a web interface).

All well and good, but the problem comes when creating a data model for MVC. Modifying a data model programmatically to add a field to a table seems to be impossible, according to this link:

Create EDM during runtime?

This is a major headache for us. Even if we don’t use MVC, I think we’d still want to create a data model (perhaps for used with LINQ to SQL).

We’re considering having a table with loads of fields in it, and instead of adding fields to the database we allocate an existing field in the table when the user wants to add a field to his form. Not sure I like that idea, though.

Of course, we don’t have to use MVC or Entity Framework, but it appears to me that these are the kind of technologies that Microsoft would steer us towards for future development.

Any thoughts? I’m assuming that we’re not the first people in the world to consider this idea of a user-customisable application.

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

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

发布评论

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

评论(3

開玄 2024-10-03 12:04:08

我确保您已充分探索了创建“名称-值对”类型表的选项,如此处所述 http://msdn.microsoft.com/en-us/library/aa479086.aspx#mlttntda_nvp
在开始查看可定制架构之前。另外不要忘记,您必须向您的 sql 帐户授予更高的权限,以便它们能够动态创建表。
可定制的架构意味着您的 sql 帐户还需要更高的权限。不建议将这些更高的权限分配给租户帐户,而是分配给可以执行这些任务的单独的配置帐户。

另外,在向 EF 投入精力之前,请尝试在谷歌上搜索“EF 不信任投票”。它的提出(我相信)主要是为了对早期版本的反应,但它绝对值得一读。 nHibernate 是一个值得研究的替代方案。

I'd make sure that you have fully explored the option of creating 'Name-Value Pair' type tables as described here http://msdn.microsoft.com/en-us/library/aa479086.aspx#mlttntda_nvp
before you start looking at a customizable schema. Also don't forget that you are going to have to grant much higher permissions to your sql accounts in order for them to create tables on the fly.
A customizable schema means that your sql accounts will also need much higher permissions. It wouldnt be advisable to assign these higher permissions to a tenants account, but to a separate provisioning account which can perform these tasks.

Also before investing effort into EF - try googling 'EF Vote of No Confidence'. It was raised (i believe) mainly in reaction to earlier versions but its definately worth reading up on. nHibernate is an alternative worth investigating.

南七夏 2024-10-03 12:04:08

我突然想到,允许用户更改数据库模式听起来是个坏主意。我认为你缺少一个抽象层。在我看来,使用数据库来保存描述客户数据格式的数据会更正确。然后,实际数据将以 xml 形式保存在文本列中,包括版本信息。
这个解决方案可能不符合您的需求,但我不知道您的项目的详细信息。所以就当作我的 5 美分吧。

Just off the top of my head it sounds like a bad idea to allow users to change the database schema. I think you are missing a layer of abstraction. In my mind, it would be more correct to use the database to hold data that describes the format of a customer's data. The actual data would then be saved in a text column as xml, including version information.
This solution may not fit your needs, but I don't know the details of your project. So just consider it my 5 cents.

热情消退 2024-10-03 12:04:08

如今,大多数现代 SQL 数据库都支持“jsonb”类型作为字段进行键/值存储。其他类型(postgres 的 hstor)也存在。忘记 XML,那已经是昨天的事了,没有任何应用程序本身会实现 XML,除非它用于导入/转换旧数据。

Most modern SQL databases today supports the 'jsonb' type for key/value storage as a field. Other types (hstor for postgres) exists too. Forget about XML, that's yesterday and no application with respect for itself implements XML unless it is for importing/converting old data.

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