Is this a good case to use EAV or no

て烟熏妆下的殇ゞ 提交于 2019-12-24 04:42:07

问题


I have different product types that have different attributes. They cannot be stored in a single table as the attributes are too distinct. There's a couple of options I'm currently looking at: EAV and a table for each type.

My situation is, at the moment, there are only a number of types (lets say 8) but in the near future with almost 100% certainty, this can grow. But the growth is controlled by me, its not defined by users. It will be up to me to grow the product type.

I'm currently inclined to use EAV (for the reason that I can cover the growth easily - I think) but I am not sure as I'm concerned with the performance as well as modeling them in my language of choice (C#). My question is, given the scenario above, is it better for me to create a single table for each product type and add as necessary, or would this be a good case (or not even good, lets say acceptable) to use EAV?


回答1:


There's no short good or bad answer to this concern, because it depends of many things.

  • Do you have a lot of product types ?
  • How do you think each of them will evolve (think to what will happen when you will add new fields to products) ?
  • Do you need to handle "variants" of the products ?
  • Do you intend to add entirely new types of products ?

Etc. EAV is probably a good way to go if you answer if you answer "yes" to some or all these questions.

Regarding C#, I have implemented in the past an EAV data catalog with it, and using Entity Framework over SQL Server (so a RDBMS). It worked nice to me.

But if you need to handle a lot of products, performance can quickly become an issue. You could also look for a "NoSQL" solution, did you think about it ?

Just keep in mind that your model object does not have to match your data model. For example you could perfectly have a stronly typed object for each type of product if you need so.




回答2:


Much depends on the operations that will be performed on entities. If you will:

  • often add new attributes to products;

  • add a lot of products type;

  • implement full product type search (or other "full product type" feature);

I recommend you to use EAV. I have implemented in the past EAV data structure with ADO.NET and MS SQL and don't have any problem with performance.

Also, Morten Bork above recommend use "sub types". But if you want implement some "full product type" features, I think it will be more difficult then use pure EAV model.




回答3:


EAV doesn't really play well with a relational database. So if that is what you are doing. (IE connecting to SQL) Then I would say no. Take the hit in development time, and design a table pr type of product, or make a aggregate table that holds various properties for a product type, and then connect the properties to the relevant tables.

So if a product contains "Cogs" then you have a table with "teethcount", "radius" etc. Another product type has "Scews" with properties "Length", "riling" etc. And if a product type has both cogs and screws, it merely has relation to each of these subtypes.



来源:https://stackoverflow.com/questions/53537241/is-this-a-good-case-to-use-eav-or-no

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!