This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
You really need a sample of a winforms app - its really unclear how scoping of contexts and units of work should be handled in winforms. Specifically I want to do the following: 1) Open an entity when opening a form and have have the properties of that entity bound to the controls 2) Bound lookup data to lists and combos on that form 3) Allow 'Save' to save, and 'Cancel' to rollback all changes and reload(?) the entity from the database again (using something like an IsDirty property) 4) How should the validation features best be used in winforms? Just to note: I'm not using MVP. Thanks. |
|
|
We recognise that we're not providing enough clear guidance for rich client (WinForms and WPF) users: we are doing a samples pass as part of LightSpeed 3 and we will aim to start shipping those over the next couple of months (i.e. not waiting for 3.0). We would welcome feedback on the sort of scenarios you'd like to see covered in WinForms samples. To address your specific questions: 1. You can do this just as you would with any other object, with the caveat that you need to watch out for unit of work scoping if the form will traverse associations or save the entity later on. A sensible strategy here is to keep the unit of work as a member variable of the form, and dispose it as part of the form's Dispose override. This will work well for dialog-type forms, but may not be a good fit for "home screen" forms which remain open for a long time: in the latter case you may want to create a new UOW and reload the screen whenever the user returns to it from a dialog, or performs an explicit refresh. 2. You should be able to do this by binding to either an association property (for master-detail type lists) or to a query (for reference-data type lists). Again UOW scoping should be the only real issue here. If this doesn't address your scenario then could you say in a bit more detail what you want to achieve, and we'll try to offer a recommendation or sample code. 3. We would recommend using BeginEdit and EndEdit/CancelEdit for this, as the IEditableObject interface is idiomatic for WinForms and supported by controls like data grids. This works at a per-entity level rather than a UOW level though; also, CancelEdit returns the entity to the state it was in when you called BeginEdit, rather than going back to the database again. (We have had several requests for a "reload from DB" feature so this is very much on the radar.) 4. You can call Entity.Validate in your form or control's Validate handler. Entity implements IDataErrorInfo which allows you to get per-property errors (e.g. for use in an ErrorProvider). We'll aim to provide a sample of this when we do a WinForms sample, but in the meantime please do ask if you need any help with this. Please let us know if you have any more questions -- knowing what areas are not clear or convenient will be very helpful to us in putting together the WinForms sample. |
|
|
I just purchased LightSpeed v2.2 and there is a glaring lack of information regarding WinForm best practices. I have seen many requests for this guidance dated as eraly as Jan. 2008. Why should we have to wait for version 3 and deal with a WPF example. Thats great, but we need a Winforms reference app or guideline. Most companies won't be embraing WPF for a year or more. How long does it take to produce a reference application in WinForms, or at least a best practice document. I am disappointed that the responses to these types of questions are always a request for a more specific question. I think this is just a way of side stepping the core question. LightSpeed support. Please spend more time on your examples and documentation and your product will sell better. It's that simple.
|
|
|
I hear you Dan. This week I will integrate a WinForms sample into the LS3 beta build (which you will have access to). The intention is to start simple and evolve the sample to include more advanced use cases. The reason that we often ask follow up questions is because application architecture is often already in place - plain old code behind files, MVC/MVP/MVVM patterns in use, etc. This does impact how one would look to leverage LightSpeed in their solution. We do know there is demand and we will supply a sample for WinForms developers. It may not be of interest to you but I published a blog post with tips for rich client development here: http://www.mindscape.co.nz/blog/index.php/2009/08/19/tips-for-rich-client-development/ I will update this thread to let you know when there is an updated LS3 build that includes the WinForms sample. John-Daniel Trask |
|
|
I also need example where LightSpeed ORM is used partially. We can use ORM for: 1) Loading data from a database 2) Saving changed data to a database I am trying to use LightSpeed for the 1-st purpose only. For saving changed data to a database i'm using stored procedures. Thereby i got following troubles: Stored Procedure and UnitOfWork entity cache How to clear all pending changes in entity and reload it from database ? May be i understand insufficiently ORM or we must follow such principle: Use ORM everywhere or do not use ORM PS: About 1 year ago i had problems with MS LINQ to SQL Server and database where triggers is used. |
|
|
You can call Entity.Validate in your form or control's Validate handler. Entity implements IDataErrorInfo which allows you to get per-property errors (e.g. for use in an ErrorProvider). We'll aim to provide a sample of this when we do a WinForms sample, but in the meantime please do ask if you need any help with this. --------------------------------------------------------------------------------------------------------------------------- I am just getting around to looking at doing this, but having a few problems. I have a simple WinForms dialog bound to an Entity using a bindingsource on the dialog . The error provider has the bindingsource set as it's datasource in it's properties at design time. A property of the dialog is used to set the datasource before the dialog is shown. When entering data to the bound text box that is too long, the error in the entity is set (I have checked the entity.Errors collection in the click event of the 'Save' Button), but the flashy-red- exclamation-mark-thingy (this is a technical term) is not displayed unless I go back to the text box and edit the data again. I must be missing something basic here, any ideas ?? I have tried calling errorProvider1.BindToDataAndErrors(bindingSource, bindingSource.DataMember) after the bindingSource has been set to the object to be displayed at run time , but that doesn't seem to change anything. FYI - the code for the save button (not using MVP/MVC at the moment) is as below with the code that I added to check if the error was there. private void buttonSave_Click(object sender, EventArgs e)
|
|
|
OK, so I am still having troubles with this. To try and get it to show the error provider icon after validation, rather than on the click of the save button (which doesn't work either), I added a call to the Validate() method of the entity in the Validating event of one of the text boxes and stepped through the code to make sure it was happening. private void databaseNameTextBox_Validating(object sender, CancelEventArgs e) The first time the Validating event is called on that text box (with a string that is too long, so it should be invalid), there is nothing in the Errors collection. If I then go back in , delete one character (so it is still too long) then tab out, the validating event fires again, and this time there is an error in the collection and the errorprovider icon is shown. If I just tab out, tab back in and tab out again without making any changes, the message box pops up with the expected error, but the errorprovider icon is NOT shown. Also, if I edit the string back down to a valid length, the icon is not hidden until I tab back in again. I think I must be missing something basic here. Am going to create a simple project with just the one form and one object to try and get to the bottom of it. I have created a test class (not using a Mindscape Entity) and implemented IDataErrorInfo in it, linked it up in what seems to be the same way as the MindscapeEntity on another test form, and that works fine.
|
|
|
OK, so I have found why that doesn't work, since the data has not been saved to the bound entity in the Validating event. Sooo, I put a _location.Validate in the Validated event, which imprves things a little bit. The Invalid errorprovider icons are still not cleared if the text is initially invalid, then changed to valid and the error message is not changed if the reason for it being invalid has changed, unless you go back in and come out again. Do I need to put some explicit code in there to clear it ?? I copied some code from the web as a test, which implements IDataErrorInfo and that works fine.All I do is set the errorprovider datasource and that's it. I'm giving up for the moment and going on to something else, but if someone could give me some guidance at some point that would be much appreciated. I can't find anything in the help file and the winforms example does not use an error provider, it just checks IsValid and does nothing if not valid. I'm using Lightspeed 3.0 (not a nightly build). Below is the test class I have used and bound to a form and all works fine.
public class Customer : IDataErrorInfo |
|