How to - extending nopCommerce (1.X versions)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
stimpy77 wrote:


Libraries\Nop.BusinessLogic\Customer\Customer.cs

Line numbers:
454-486 namely 472 & 482

.. will bring about whatever instance of ICustomerService is associated with IoC, which in our case is a different instance of ICustomerService than what we are currently calling Customer with.


Well, that is just wrong. IoC resolves always to the same instance of an entity across a single request. I don't know what was causing your exceptions, but different instances of the services were not. Unless you created an istance without using IoC. That would explain the problem.

Sincerely,

Bojan Hrnkas
13 years ago
Hello,

I am having another problem with modifying database. In my case, I only get this error with the Customer table. This is my step to reproduce the error

1. Add one table in database, name ksu_Banner. This table has some fields: BannerID, Name, CreatedBy, CreatedDate
2. Create a relationship between CreatedBy and CustomerId in Customer table

3. Open edmx file, update changes from database and select new table
4. Delete the navigation property in Customer and Banner in edmx file
5. Create a class in Extension folder for new table
6. Build solution
7. Try to register new member, and i have this error


The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message: There is no metadata information available for the proxy type for 'NopSolutions.NopCommerce.BusinessLogic.CustomerManagement.Customer'. This exception can be caused when a proxy type for an entity is detached from an ObjectContext. See InnerException for details.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message: There is no metadata information available for the proxy type for 'NopSolutions.NopCommerce.BusinessLogic.CustomerManagement.Customer'. This exception can be caused when a proxy type for an entity is detached from an ObjectContext. See InnerException for details.

Source Error:


Line 1233:
Line 1234:            _context.Customers.AddObject(customer);
Line 1235:            _context.SaveChanges();

Line 1236:
Line 1237:            //reward points

Source File: D:\WORK\NOPCOMMERCE\nopCommerce_1.90_Source\Libraries\Nop.BusinessLogic\Customer\CustomerService.cs    Line: 1235

Stack Trace:


[InvalidOperationException: The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message: There is no metadata information available for the proxy type for 'NopSolutions.NopCommerce.BusinessLogic.CustomerManagement.Customer'. This exception can be caused when a proxy type for an entity is detached from an ObjectContext. See InnerException for details.]
   System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) +779
   System.Data.Objects.ObjectContext.SaveChanges() +15
   NopSolutions.NopCommerce.BusinessLogic.CustomerManagement.CustomerService.AddCustomerForced(Guid customerGuid, String email, String username, String passwordHash, String saltKey, Int32 affiliateId, Int32 billingAddressId, Int32 shippingAddressId, Int32 lastPaymentMethodId, String lastAppliedCouponCode, String giftCardCouponCodes, String checkoutAttributes, Int32 languageId, Int32 currencyId, TaxDisplayTypeEnum taxDisplayType, Boolean isTaxExempt, Boolean isAdmin, Boolean isGuest, Boolean isForumModerator, Int32 totalForumPosts, String signature, String adminComment, Boolean active, Boolean deleted, DateTime registrationDate, String timeZoneId, Int32 avatarId, Nullable`1 dateOfBirth) in D:\WORK\NOPCOMMERCE\nopCommerce_1.90_Source\Libraries\Nop.BusinessLogic\Customer\CustomerService.cs:1235
   NopSolutions.NopCommerce.BusinessLogic.CustomerManagement.CustomerService.AddCustomer(Guid customerGuid, String email, String username, String password, Int32 affiliateId, Int32 billingAddressId, Int32 shippingAddressId, Int32 lastPaymentMethodId, String lastAppliedCouponCode, String giftCardCouponCodes, String checkoutAttributes, Int32 languageId, Int32 currencyId, TaxDisplayTypeEnum taxDisplayType, Boolean isTaxExempt, Boolean isAdmin, Boolean isGuest, Boolean isForumModerator, Int32 totalForumPosts, String signature, String adminComment, Boolean active, Boolean deleted, DateTime registrationDate, String timeZoneId, Int32 avatarId, Nullable`1 dateOfBirth, MembershipCreateStatus& status) in D:\WORK\NOPCOMMERCE\nopCommerce_1.90_Source\Libraries\Nop.BusinessLogic\Customer\CustomerService.cs:1102
   NopSolutions.NopCommerce.BusinessLogic.CustomerManagement.CustomerService.AddCustomer(String email, String username, String password, Boolean isAdmin, Boolean isGuest, Boolean active, MembershipCreateStatus& status) in D:\WORK\NOPCOMMERCE\nopCommerce_1.90_Source\Libraries\Nop.BusinessLogic\Customer\CustomerService.cs:938
   NopSolutions.NopCommerce.BusinessLogic.Profile.StoreMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) in D:\WORK\NOPCOMMERCE\nopCommerce_1.90_Source\Libraries\Nop.BusinessLogic\Profile\StoreMembershipProvider.cs:101
   System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() +302
   System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) +111
   System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +413
   System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) +121
   System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +19
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +125
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +167
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563




I only have this error with the Customer table. I do same way with Product table (i.e create a new table and have productID as a foreign key) but I don't have error when adding new Product table.

Please help me to fix this issue.

thank you very much.
13 years ago
Well, I've never seen this Exception myself, although I made some serious Database changes.
Are you sure that your entity objects are mapped to the db tables in right manner?
Have you changed CustomerService code?
Do you have all navigation properties in your entities?

Maybe you could give us more info on what changes did you make on the code.
13 years ago
Hello, so this is more detail to reproduce my bug
1. Get a brand new nopCommerce source code 1.9
2. In database, add one more table. Here I added a table name Banner with following fields
+ ID
+ Name
+ BannerContent
+ CreateBy (int - this will be the customerID that create the banner)
+ CreateDate
3. Create a relationship between table Banner and table Nop_Customer, CreatedBy and CustomerID
4. Update edmx file, add the new table I've just created - Banner
5. Delete the Navigation Properties in Customer entity, just delete the property Banner
6. Delete the Navigation Properties in Banner entity
7. Build, then try to register a user. Error occurs!!!

I tried the same steps, with Nop_Product table. But then I still can create a product in admin properly.
13 years ago
My guess is that Customers ObjectSet wasnt properly updated from the model. See if you can find an error in \Libraries\Nop.BusinessLogic\Data\NopObjectContext.ObjectSets.cs

Beyond that I really don't know what else to try. Like I said, I added multiple tables to the database and linked them to existing tables without any problems. However, I haven't deleted the navigation properties, but created extension to partial class Customer and put the navigation properties in there.
13 years ago
Is there a tutorial for extending v. 1.9?
13 years ago
Are you updating the NopCommerce's original edmx or do you have your own separate edmx?
The common guess is to verify that all the properties of the entity (can be checked in the model browser) have the same name (case-sensitive) as properties in your class. For example, your have CustomerID property in DB and in your data model by default, but in class there's CustomerId.
I had that metadata exception while trying to go with my separate edmx file + using slightly modified template (.tt) files from NopCommerce. And the point was to delete MyModel.Designer.cs file.
13 years ago
parlesmith wrote:
Is there a tutorial for extending v. 1.9?


The link from the first post of this thread is valid also for 1.9.

For some more details on extending the services, read my post from the page four of this thread.
13 years ago
hey guys, is the link from page 1 dead?
13 years ago
ssmattr wrote:
hey guys, is the link from page 1 dead?


The entire blog server seems to be down.
Maybe it is just temporary.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.