Foreign Key usage in NopCommerce database

1 year ago
Hello -
       I am trying to get myself familiar with the nopcommerce code base and database schema. One thing I noticed in the NopCommerce database is that usage of Foreign Keys is scarce. Only a few tables and relationships between tables are using FKs.

A good example of this is important tables like "customer" and "product" do not have a foreign key on VendorID from the "Vendor" table.

My question is:
- Is the use of foreign keys on only a few tables a conscious decision due performance problems (or other application related issues)?
- My question to the community is if anyone actually took action and added FKs in? Or if anyone ran into any problems because of adding in FKs?

Thanks!
1 year ago
This is probably a design decision by the team, so I may not be a good source to answer this question. However, my understanding is that this may be done from a performance (and necessity) standpoint.

As we are using eager loading in Entity Framework, it means all the related entities will be retrieved when we retrieve a single entity. And with the object graph as complicated as nopCommerce's, it can degrade performance to do this. So for those entity that is less used, we may save some memory by not retrieving them.

Just my assumption though, may not even be a valid reason. :)


1 year ago
Also could be because some ids...
   "... tables like "customer" and "product" do not have a foreign key on VendorID"
are not required, so a '0' dummy record would be needed.
1 year ago
Also could be because some ids...
   "... tables like "customer" and "product" do not have a foreign key on VendorID"
are not required, so a '0' dummy record would be needed.
1 year ago
Hi -
    WoonCherk I was kind of thinking along the same lines. There are a lot of assumptions. I wish someone from the NopCommerce code architecture team could give us some insight on these decisions. That would be great for someone trying to make the decision of using NOP cvalommerce. I will research more and will post if I find anything.

New York - Yes a dummy 0 value is being used by NOP commerce currently, in the foreign key world that is an equivalent of using a nullable foreign key.

Thanks!