Added a new Foreign Key to Product Entity, but cannot get data saved to Table

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 年 前
Hello All,

I added a new entity (ProductPriceCategory) so that I can group my products -- yes, I know I could have just used categories, but we wanted a drop down on the first tab of the Product Edit page so I did it this way.

My entity has two fields (Id and Name) and I added PriceCategoryId field to the Product Table and made it a foreign key to the ProductPriceCategory Entity.

I added a model to the Nop.Core.Domain.Models project, added a mapping to the Nop.Data project and added a service to the Services project.

I added a model in the Admin.Models namespace and edited the Product Controller to get a list of PriceCategories into the model.  Basically, I replicated the Product templates logic.

I am able to display the list in the First tab and when I select an item and save the product, I can see the PriceCategoryId field going back containing the value I selected (i.e. 6).

But I have two problems:
1. When the form is displayed the value in the PriceCategoryId is not the selected value by default -- it defaults to the first item in the list.
2. When a value is selected and the product saved, the changed value is not saved to the database

I thought I got everything right but obviously I'm wrong, please point me in the right direction.
7 年 前
By the way, I'm using NopCommerce 3.6.

I just ran SQL Profiler and caught the update query for the Product table.  It did not contain my new field (PricecategoryID), so this means the App is not passing the field to SQL.

I have the domain model set correctly and I see the field coming in from the Web application, I also see the field in the model in the Product Service and all the way to the Nop.Data.EFRepository, being passed as a proxy entity.

Where can my problem be?
7 年 前
So, I ran another SQL Profiler session and made and update to another field (short Description) and also changed my PriceCategory field to a different value.

In the trace, I saw the short description update but not my new field.

Does anyone know what decides there has been a change in one of the fields that needs to be persisted?

I expected the whole entity to be saved to the database, but I only see the field being changed in the actual SQL query and not the entire record.

As I wrote above, I see my updated field in the model being passed all the way to the Nop.Data.EFRepository class, so what else is there after that and before it goes to the SQL server?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.