문제

As part of a description of what he needs, a customer asked to be able to add properties to save.
I have two ideas to how to do that:

  1. creating a EAV table.
  2. a XML document that will store the extra data.

I don't really like both approaches:
the first is something I read all around I should avoid. (for example: here, third thing)
the second I want to avoid so I won't have a mix.

Is there a preferable way to do this?

(I'm using c#, linq to sql, vs 2010)

도움이 되었습니까?

해결책

It's a hard question to ask.

If your client's data is truly or effectively schema-less - i.e. the attributes for each record are likely to vary unpredictable for each row - then the relational model is not suitable in this case, and you need to look at a different solution - NoSQL, perhaps, or going document-oriented.

If your client is really saying "I want to be able to add attributes to the data model later, and I don't want to make up my mind about those attributes just yet", but it's basically a relational data model, you might consider automating the schema generation process; this is a pain, but in Ruby on Rail, there's an example of Active Record schema migrations. There may be an established library for your programming language.

If your client is saying "we have this fixed core of data, but on a case-by-case basis, we like to add additional data which we can't describe right now", then I'd go with an XML/Jason/YAML-style record, appended to the core relational records. Most database engines now natively support XML, including querying via XPath etc.

In my experience, XML documents included in the relational model offer a lot of flexibility, and reasonable performance; the programming model is a little awkward, but far less awkward than EAV for most cases.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top