rivantsov / vita

VITA Application Framework
MIT License
59 stars 15 forks source link

Force SaveChanges to save a object #181

Closed rubenalves closed 3 years ago

rubenalves commented 3 years ago

Hello,

I hve everything working with version 3.2 but in some cases in my POS system, it i change the quamtity of a line object and calculate the total and save shaves it saves the changes and updates the UI ok, i change table, add some more lines and save changes, when i go back to that table, get the objects back but with whe old values for quantity, it dos not commited to to the database. I hade to make workaraoud, every time i change the quantity or price i use dapper to commit that value and when i load the table again it is there, just to notice, i Create a Session only at The load of that Window and only reload the data. It probably has to do with binding the objects to bindingsource.

Is there a way i can force the savesanges to commit the objects with changed properties? It is ok the way i have it working but i lost a little confiance on vite because every day i get a new sismilar situations reported with a customer.

Thanks.

rivantsov commented 3 years ago

session always commits all changed objects. well, based on recent accident with another session, my primary suspect is that you have another session, and you have header with total loaded thru this another session; and 'first' session that loads lines and on which you call SaveChanges, it has no idea about the other loaded record that might have been modified. Binding objects to binding source - that's something in UI, VITA has nothing to do with this. Before doing this extra dapper stuff - try to find out what's really going on. Make a stop at SaveChanges and inspect session.RecordsChanged list - is the header record with total there?

rubenalves commented 3 years ago

For the testes i made, it is probably something to do with the notifypropertychaged that is injected by vita in the objects, in one or to cases i noticed that it does not change the screen also, so the notifypropertychaged event is not fired, on vita 1.9 that never happened on 3.x it seems to be the problem.

rivantsov commented 3 years ago

ok I will look into this... but generally I would advise to get away from this use, INotifyPropChanged and all that binding. It might be that new value is not pushed down to the data object/entity? I remember this being tricky with UI binding, smth like push down happens when you tab out the edit box (change focus), or even move to next record. Suggest to handle it more explicitly in UI, add the explicit call to recalc total

rubenalves commented 3 years ago

I change the value in code, save changes, then reload the object and it is not changed in the database because vita did not get that the property changed, and mark it with changes, so the binding is from the object to the control after the save changes, and using sql managment studio i read it from the database and is tthe same as it was bevause savechanges did not detect it, that is why i used dapper to commit the changes before i reload the data with vita and it is ok. please note that it dows not happen lots of times, but it is a very strange thing, if i have to use dapper to update every field that is changed to have be sure that it is saved that is very bad :)

that is the reasond that makes me think it is related to INotifyPropChanged

Thanks for your time.

rubenalves commented 3 years ago

I have foud the problem, it was related to database triggers, so i am abandonig the trigers and use vita to update the values manually, it makes more sense now than wat it made when i created first started to use them.

I have removed all the dapper i had added before and it is working as expected now.

Thanks for you time and sory if you lost time with this issue.

rivantsov commented 3 years ago

no problem, I'm glad you found it. i could not see anything inside Vita that could be the cause. Congrats, good luck, let's keep going.