626 users online

this._context.SaveChanges(); doesn't work from WPF App.

Posted: 3 months ago Quote
My call to  orderProcessingService.Ship from my WPF app goes great until it reaches

EfRepository.cs ln 64

this._context.SaveChanges();

_context.SaveChanges doesn't update the db.

I can't get the debugger to step into .SaveChanges() so I don't know whats going on in the method and why the changes are not being made to the db.

The are no errors. Just no update to the db.

Any Ideas?

Darren
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Darren Pegram
www.inkredible.co.uk

Follow me on twitter for thoughts and insight into how I run my business and generally live through life

@darrenpegram
Posted: 3 months ago Quote
Hi,

Does anyone have any ideas on this one? Final bug in my code before I can launch our WPF app and share with the community.

Darren
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Darren Pegram
www.inkredible.co.uk

Follow me on twitter for thoughts and insight into how I run my business and generally live through life

@darrenpegram
Posted: 3 months ago Quote
In EfRepository, it's using the IDbContext interface which is implemented as NopObjectContext

If you look in the Nop.Data solution, find the class NopObjectContext and method SaveChanges, maybe put a breakpoint in here, see if anythings going on

Otherwise, maybe try enabling all exceptions (Crtl+Alt+E, make sure 'Common Language Runtime Exceptions' is checked for 'Thrown') just before the save call
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: 3 months ago Quote
dmorley wrote:
In EfRepository, it's using the IDbContext interface which is implemented as NopObjectContext

If you look in the Nop.Data solution, find the class NopObjectContext and method SaveChanges, maybe put a breakpoint in here, see if anythings going on

Otherwise, maybe try enabling all exceptions (Crtl+Alt+E, make sure 'Common Language Runtime Exceptions' is checked for 'Thrown') just before the save call


Hi,

Thanks for your response.

NopObjectContext =.cs doesn't have a SaveChanges method (2.3 or 2.4)

I've now enabled all exceptions. Don't get anything at   this._context.SaveChanges();

Could it be something to do with the context it is saving? Do I need to create a context in the WPF app? Is there a way to check the "order" object I'm changing is in the correct context.

Really appreciate your help

Darren
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Darren Pegram
www.inkredible.co.uk

Follow me on twitter for thoughts and insight into how I run my business and generally live through life

@darrenpegram
Posted: 3 months ago Quote
I think SaveChanges is an Entity Framework method


EntityFramework.dll$v4.0.30319$NoDynamic\System.Data.Entity.DbContext.cs(267):        public virtual int SaveChanges();


so I can't see the code.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Darren Pegram
www.inkredible.co.uk

Follow me on twitter for thoughts and insight into how I run my business and generally live through life

@darrenpegram
Posted: 3 months ago Quote
OK,

If we take a step back. Is there any reason why this shouldn't work from external application

  var _orderProcessingService = App.AutoFacContainer.Resolve<IOrderProcessingService>();
  _orderProcessingService.Ship(order, true);

Services that retrieve data work fine. Only those that write back to the dB don't commit the changes.

Any ideas anyone?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Darren Pegram
www.inkredible.co.uk

Follow me on twitter for thoughts and insight into how I run my business and generally live through life

@darrenpegram
Posted: 3 months ago Quote
Can anyone help me on this?

Could it be to do with EF not tracking changes?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Darren Pegram
www.inkredible.co.uk

Follow me on twitter for thoughts and insight into how I run my business and generally live through life

@darrenpegram
Posted: 3 months ago Quote
wunpac wrote:
Can anyone help me on this?

Could it be to do with EF not tracking changes?


I'm not entirely sure about the structure of your WPF/external application. But...

Yes, it's about EF. Your application and nopCommerce Web will not use the same data, if you change something, Web will not see or be notified about the changes. If Web changes something, your app will not detect the changes since you are running a separate "EF instance", with its own caches and so on.

That is one of the reasons behind using the WebServices plugin. You have to use the same EF instance as Web and route all calls and data manipulation through Web. EF caches and lazy loads data from the DB so your external app will not use the same data as the Web application.

You have to extend (or write another) WebServices plugin containing the methods you need and communicate with the Web application using those services, otherwise the two applications will never use the same data. With synchronization problems, data corruption, as a result.

[As a side note, we are building a somewhat large new system (webshop) based on nopCommerce (180,000 orders/year, 30 million euro in revenue). We have an in-house, specialized solution today but are going with nopCommerce for the next step, generation. Our customizations (project span) is planned to about 6,000 hrs including testing and all things.

Architecturally, what we are going to do. Is to let nopCommerce to manage the shop. We have a lot of customizations we will have to do but the main thing is to let the nopCommerce engine to "its thing". We will not build the ERP functionality into nopCommerce since it would require almost a complete departure from the main thread of development and we will stay as compatible as possible with future updates. So we handle this through batch jobs and a customized webservice plugin. Most of "our" business logic reside in the batch jobs. They lift orders from nopCommerce into our ERP system and also updates data the other way around. For critical operations (as stock or article information) we have direct connections, still going through services but using BizTalk instead of batch jobs.]
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: 3 months ago Quote
Hi imfs,

Thank you for your response!!! Its hugely appreciated. I've been barking up the wrong tree for a week now. Although I do appreciate the contribution from those who have helped so far.

Could you give me any guidance (in general terms) on how to use the webservices API? I'm sure the general principles can be applied to WPF. I just need a starting point.

Thanks

Darren
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Darren Pegram
www.inkredible.co.uk

Follow me on twitter for thoughts and insight into how I run my business and generally live through life

@darrenpegram