How To: NopCommerce Best Practices for GenericAttribute table
NOTE: DRAFT IN PROGRESS
Description:
A generic storage table for long term and short term data for any
entity in NopCommerce that inherits from BaseEntity. But be careful how you use this table or
what you do with it because it has both long term and short term data and not understanding the of the data that's stored could cause issues.. The GenericAttribute table can persist long term Customer data such as First Name, Last Name and Gender. You can use the GenericAttribute table to persist the long term order data but the
KeyGroup must be Order and the EntityId represents the OrderId
Table: GenericAttribute
- Id (int, identity, not null, pk)
- EntityId (int, not null)
- KeyGroup (nvarchar(400), not null)
- Key (nvarchar(400), not null)
- Value (nvarchar(max), not null)
- StoreId (int, not null) - Settings Store to 0 means all stores
Related Tables:
Uses:- Customer Entity : Register : You'll find that it stores long term information like Gender, FirstName, LastName and more on customers who have registered. Note that StoreId is set 0 which means it applies to all stores. This is long term storage meaning it won't change unless change are made by the user specifically.
- Long Term Records:
- KeyGroup: Customer
- Key's are:
- Gender
- FirstName
- LastName
- DateOfBirth
- Customer Entity : Checkout : You'll find that it temporarily stores short term data such as a a user selections as you transitions from one section to the next during the checkout process for that customer. Any values stored during this will be overwritten by the next order for that customer.
- Temporary Records:
- KeyGroup: Customer
- Key's are:
- SelectedPickUpInStore
- UseRewardPointsDuringCheckout
Extending:- The GenericAttribute table is well, generic by nature. Extending it probably is not necessary. However be warned that it does not enforce referential integrity and I would probably try to avoid if possible..