如果EAV是邪恶的,什么用于动态值?

问题描述:

我需要创建数据库,其中 Accountgroup 表将具有动态字段,以便 Accounts 可以输入这些动态字段值需要的时候。这可能不重要,但我使用C#与EF和Linq。

I need to create database where Accountgroup table will have dynamic fields so that Accounts can enter those dynamic field values when needed. It's probably not important but I'm using C# with EF and Linq.

这对我来说很难,因为我从来没有做过这样的,因为我做了我的研究每个人都说EAV系统是可怕的,你应该设计不同的,问题是没有人告诉后来 - 如何?

It's hard for me because I never done anything like that and since I did my research everyone is saying that EAV systems are horrible and you should design it differently, the problem is that nobody tells afterwards - how?

也许你可以帮助我并告诉我如何在没有做EAV的情况下实现类似的东西?

So maybe you can help me out and tell how can I implement something similar without doing EAV?

这是我到目前为止的情况。

This is what I have so far.

经验法则的问题是,他们很快就从通常是一个坏主意来做 X 到永不做em 。

The problem with rules of thumb is that they quickly go from "It is usually a bad idea to do X" to "Never do X".

EAV通常是个坏主意,因为在许多方面,它违背了关系模式的目的,因此它会带走许多功能,关系DBMS的优点和建立在RDBMS上的其他技术,例如像Entity Framework这样的ORM。

EAV is generally a bad idea because in many ways it defeats the purpose of a relational schema and thereby it takes away many of the features and advantages of a relational DBMS, and other technologies built on RDBMS, such as ORMs like Entity Framework.

然而,有一些设计问题,RDBMS不是一个很好的适合。有一些是非常适合,一个全新的技术必须发明(例如NoSQL数据库,如MongoDB)。

However, there are certain design problems for which RDBMS isn't a great fit. There are some that are such a bad fit that a whole new technology had to be invented (e.g. NoSQL DB like MongoDB).

有时EAV可能是最好的选择留给你一个不完美的选项。如果你不(不能)知道你的模式是手前,那么EAV可能是你最好的选择。如果你的模式是不重要的,这是尤其真实的。例如,考虑一个在线产品目录,其中有一个巨大的产品列表,每个产品都有一些功能。您无法预先预测哪些产品将具有哪些功能。最后,你使用产品功能的唯一的事情就是将它们转储到feature:value列表中。这是一种情况,其中模式不是特别强大,所以用EAV击败它不是特别危害。

There are times when EAV is probably the best choice left to you out of a set of imperfect options. If you don't (can't) know what your schema is before hand, then EAV may be your best choice. This is especially true if your schema turns out to be unimportant. Consider for example an online product catalog where you have a huge list of products, each of which has some number of features. You can't predict in advance which products will have which features. And in the end, the only thing you do with product features is dump them out in a "feature: value" list anyway. This is a situation where schema isn't especially powerful, so defeating it with EAV isn't especially damaging.

最重要的是要了解你的设计选择要做你的能力和操作。所有的设计都是权衡。关键是要有意识地进行权衡。而不是EAV是邪恶,而是思考:EAV是一个负载枪,确保你知道你的脚你指向它。

The most important thing is to understand what your design choices are going to do to your capabilities and operations. All design is trade-off. The point is to make your trade-offs consciously. Instead of "EAV is Evil", think instead: "EAV is a loaded gun, make sure you know whose foot you're pointing it at."