开发者

TPH vs TPT vs TPC and OR mappers

开发者 https://www.devze.com 2023-04-12 23:33 出处:网络
I\'m working on a datamodel that has a set of types that share some common fields such as Id, Name, Description. To be more concrete:

I'm working on a datamodel that has a set of types that share some common fields such as Id, Name, Description. To be more concrete:

The Document class has a list of Attributes. These Attributes are in our domain, types like String, Integer, DateTime and more "complex" types such as Address and lists of String, Integer, Address, etc. Now, in my head I would model the Attribute classes so that I have an abstract base class (AttributeBase) that contains common attributes (Id, Name, Description) and then have the more specific attributes in the appropriate sub classes. E.g. StringAttribute (Value), IntegerAttribute(Value), AddressAttribute(Street, etc), StringListAttribute, IntegerListAttribute, AddressListAttribute. We are talking about 15-20 different sub class开发者_JS百科es. But how would you model those classes in the database? Would you choose TPH, TPT or TPC? I have read about the performance hit when choosing TPT and EF 4.1 and having one massiv table for TPH doesn't sound right to me even if the performance is better. We are talking about potentially 10000 - 1000000++ rows of data in the tables.

Do you have any first hand experience when it comes to these scenarios? I would really like to here from you on this subject.


TPH doesn't sound good from DB perspective but it is actually a storage model used by many products using this type of metadata. Example is SharePoint (2007) which has all data in single table - it follows more complex model but the basis is the same. I don't like SharePoint and the way how it stores data but by thinking about the problem I didn't find better solution to model generic solution supporting huge amount of data.

TPT and TPC will looks more normalized in DB but their usage will result in slow application. Moreover normalizing IntAttribute to table with Id, Name and Description and second table with Id and integer Value is IMHO over normalized in most cases.

Btw. if you are doing anything with documents and you want to assign properties to documents you should definitely check Sharepoint because it allows that out-of-the box.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号