Entity Mapping Product_Category_Mapping with many to many

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
No it doesn't make sense really...

You have two options realistically.

1. You add an anal code field to the category table and do a look-up for the categoryId by analcode

or

2. You create a lookup table which just has categoryid and analcode in it and do the lookup from there.

Either way I don't think your trigger is very efficient as it is trying to update all existing product-category mappings for a given category id on a product insert. Why? the product you just inserted will not have a mapping.

Method 1 also means you have to modify a fair bit of nop. ie create/update category etc etc

Method 2 means you only go look for an analcode when you do a product insert or update. either via a trigger or modify the product create/update code in nop.

You do have to keep the analcode-categoryid table up to date so requiring an analcode to be entered when a category is created would be sensible. Of course if a new anal code is created the corresponding category should be created otherwise stuff will break.

Admin users will invariably not create a category to match and wont enter the mapping if they don't have to.

HTH
11 years ago
2. You create a lookup table which just has categoryid and analcode in it and do the lookup from there.


This is way I'm going via a pluggin.

Can ask Bye the way how you mean and do the lookup from there
11 years ago
When inserting a new product from your import.

You need to create a product-category mapping to put the product in a category.

So you look up the products analcode in the analcode/catid mapping table to get the categoryid you should use.

Then you create the product-category mapping using this categoryid.

Updating is a little more complex.

1) you may have products linking to multiple categories

2) your category linking info from your import is limited to 1 link. If you change the analcode on the product record you import, how does the update remove the previous link? does it need to be removed?

So in general on update you can create a new prod-cat link but you cant delete the old one unless you delete all prod-cat links for that product. which may be ok but removes a great feature ie 1 product can be in multiple categories.

Probably not any clearer.
11 years ago
I understand.

Yes currently with this site we just need the products with its Category. I know it removes a fantastic feature but this is a wholesale site on construction of our retail site then we can implement this feature.

I have a plugin that EF creates the following Object in the db.


/****** Script for SelectTopNRows command from SSMS  ******/
SELECT TOP 20000 [Id]
,[CategoryId]
,[CCCHeading]
,[CCCDepartmentCode]
,[CCCAnalCode]
FROM [ConcordWholesales_new].[dbo].[AnalCode_Category_Mapping]


If I understand I need to populate this with the correct CategoryId - AnalCode to insert and update into dbo.Category. Would I need to do this manually or could I script a trigger to insert and update across the database's.

Everyone's help is highly regarded.

Richard
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.