Basic Question

May 21, 2010 at 7:02 PM

Firstly, I LOVE THIS TOOL!!

Im bit of a newbie so bear with me.... I have a few questions.

1. I am working with a datagridview in a winform application (visual studio 2010).  I am having trouble deciding where and when to persist the data.

2. Do I create a global collection for my entire form (containing the datagridview) or create a new collection each time I need CRUD?

I am sure more questios will follow.  I appreciate any help.  Thanks!

 

Coordinator
May 22, 2010 at 9:00 PM

Since you are using a WinForms app, you can keep the data in memory unlike a web app. Now if you just want to keep a customer and order or something in memory that is not a problem. You can load it on form load and save it on save button click. This is fine. In web apps, we usually load data on page load and then reload, modify, and persist on button click. This could cause an issue if you think people will be modifying the record at the same time. There is concurrency code built in but it is only good if you load an object, modify it, and try to persist because it uses timestamps. If you reload the data later it could have a different timestamp, which you would not know unless you save this information somehow in a variable in your WinForm. In summary, I would suggest to keep the data (the nHydrate collection or subdomain) in memory while your form is open. The framework will then keep track of concurrency and you will not loose or accidentally overwrite data. This is more difficult on a web form but you do not have this limitation. Be sure to wrap the Persist method in a try/catch block because if someone changes the data while you have it loaded, you will an exception which you can use to prompt the user.

May 22, 2010 at 9:27 PM

Thank you very much codetools.  I really appreciate your taking the time to explain the issue.  I have a another question(s) if you dont mind....

Should I code CRUD using a binding sorce or should I code on the datagridview directly?  I ask because the only advantage I see by using the binding source is during design.  What would you recommend?