Assigning CustomerRole in 4.1

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
Hi,
I have just taken over a project that has been running in 4.0 for some time and recently upgraded to 4.1.

After the 4.1 update the following code is no longer working:
customer.CustomerRoles.Add(this.RegisteredCustomerRole);

It does not generate any error. It just does not add the role to the customer.

I have replaced that code with:
CustomerRole registeredRole = this._customerService.GetCustomerRoleBySystemName("Registered");
CustomerCustomerRoleMapping customerCustomerRoleMapping = new CustomerCustomerRoleMapping();
customerCustomerRoleMapping.CustomerId = customer.Id;
customerCustomerRoleMapping.CustomerRoleId = registeredRole.Id;
customer.CustomerCustomerRoleMappings.Add(customerCustomerRoleMapping);

The new code works but I wonder why the old does not.
Is my new implementation "correct" or is there a "more correct" way to do it?

BTW, the code is used to create a customer account from a JSON file including adding the customer to the "Registered" role.

Any tips/comments are very welcome ;-)
5 years ago
It's done because EF Core doesn't support many-to-many navigation properties yet and we have to use this workaround
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.