The 5th annual nopCommerce conference will take place in India on the 10th-11th of October. Please find more about this event here

Foreign Key usage in NopCommerce database

Posted: March 06, 2019 at 11:41 PM Quote #221740
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!
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
zekokhan
Posted: March 07, 2019 at 1:23 AM Quote #221750
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. :)


This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Lam Woon Cherk
https://www.pronopcommerce.com

Looking to double your store's sale? Check out this plugin: http://bit.ly/2YVP8GT
(And no, it's not about putting more marketing money to get more traffics)

Sign up to my mailing list for tons of tips on nopCommerce: http://bit.ly/2fg5fMy
Posted: March 07, 2019 at 7:54 AM Quote #221767
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.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
www.noptools.com
Posted: March 07, 2019 at 7:54 AM Quote #221768
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.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
www.noptools.com
Posted: March 07, 2019 at 12:58 PM Quote #221783
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!
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
zekokhan
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.