Tip for adding database tables to nopCommerce: use field names Id and CustomerId

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Here is a couple of tips I learned the hard way.  When adding tables to nopCommerce, it is best to use the field name Id as the primary identity key.  Also, if you plan on adding tables that relate to the customer table, it is best to use the field name customerId as the foreign key.
11 years ago
louisd wrote:
Here is a couple of tips I learned the hard way.  When adding tables to nopCommerce, it is best to use the field name Id as the primary identity key.  Also, if you plan on adding tables that relate to the customer table, it is best to use the field name customerId as the foreign key.


This is true for all projects using EF Code-first. nopCommerce is one of them! :)
11 years ago
I can't believe I have to have an argument just for giving a tip. I have other EF apps with integer identity primary keys. However, they were not labeled Id and the when I added a table to map records against the customer table, I originally set the foreign key to nopCustomerId.  Although not impossible to integrate, it is easier to just stick with the convention of Id for the primary integer key and CustomerId for the field name of the foreign key.  Hence the tip.
11 years ago
louisd wrote:
I can't believe I have to have an argument just for giving a tip. I have other EF apps with integer identity primary keys. However, they were not labeled Id and the when I added a table to map records against the customer table, I originally set the foreign key to nopCustomerId.  Although not impossible to integrate, it is easier to just stick with the convention of Id for the primary integer key and CustomerId for the field name of the foreign key.  Hence the tip.


Hi louisd,

No, this is not an argument. I am also providing a tip on top of your tip. I just wanted to add that the convention you discovered is a inherited by nopCommerce as it is using EF Code-first. Try this: http://blogs.msdn.com/b/efdesign/archive/2010/06/01/conventions-for-code-first.aspx :P
11 years ago
But it is a tip because you don't always have the luxury of knowing ahead of time when you are integrating other code and data originating outside nopCommerce, it is best to retrofit this code and data by sticking with the naming convention Id for primary key and CustomerId for mapping to the Customer table. In fact, naming the foreign key CustomerId is more critical because nopCommerce gives you hard to trace errors if you don't.
11 years ago
louisd wrote:
But it is a tip because you don't always have the luxury of knowing ahead of time when you are integrating other code and data originating outside nopCommerce, it is best to retrofit this code and data by sticking with the naming convention Id for primary key and CustomerId for mapping to the Customer table. In fact, naming the foreign key CustomerId is more critical because nopCommerce gives you hard to trace errors if you don't.


Haha. Of course it's a tip! I mean, I didn't criticize on your original tips. I am just adding some explanation on top of your point clarifying to other readers that this is in fact a EF Code-first way of doing it and nopCommerce inherited this property because it uses EF Code-first. And if you follow Code-first conventions, you normally won't have any problem with nopCommerce. :D
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.