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
|
Greetings, We are building an ASP.NET 4.0 WebForms application (C# code behind) using VS 2010 Professional SP1 using the latest stable LightSpeed ORM. A MySQL 5.5 database is being used. The version of Mindscape.LightSpeed.dll is 4.0.1534.21185. We just started developing using LightSpeed ORM. There are a grid, two textboxes and one save button (see attached: TheWebForm.jpg). When we click a row in the grid, the textboxes are filled with the values of the selected row. The two textboxes are bound by using the EntityDataBinder to the 'Status' Entity object ('Status' is a table in our database). This works fine. We change the values in the TextBoxes and press the Save button. In the VS 2010 watch window, we notice that the values are bound to the 'Status' object correctly (see attached jpg file of the watch window). What, we think, is the important part is that we notice that the UnitOfWork property of the 'Status' object is null. The other objects (e.g. ChangeTracker) are not null. This should be the reason of the changes not being committed to the database. If we try a piece of code, like this:
it saves the changes to the database correctly. The 'UnitOfWork' object reference in 'Status' is not null then. Question is: why is the UnitOfWork null after a postback by the save button (see attached watch window jpg image)? Are we doing something wrong or did we find a bug? If you need additional information, please let us know. Thanks in advance! L. Kuiper (Acsense Software - The Netherlands) Some additional info: The Global.asax.cs holds the LightSpeedContext. We are using a PageBase class with this code (we think we don't need to store the scope in the Session, but we thought that's why we lost the UnitOfWork):
In the aspx page we have this EntityDataBinder
These bind the two TextBox controls, txtCode and txtOmschrijving to the 'Status' object. The 'Status' object is defined like this:
The edit button fills the textboxes and binds to the Status object (works correctly), xgStatus below is our datagrid:
We have a save button on the page (btnSave) which has this code-behind code:
|
|
|
We definitely don't recommend round-tripping entities via ViewState - the UnitOfWork property is null because the object has been detached from its original UnitOfWork and would need to be explicitely attached to the new UnitOfWork via UnitOfWork.Attach(). Rather than doing that though you should load a fresh copy of the object as needed within the current UnitOfWork scope (you are using a per request scope which is good) and then unbinding against that if it is an existing entity or creating a new object and then unbinding against that if it is a new entity. See an example of the code used for this in the documentation: http://www.mindscapehq.com/documentation/lightspeed/Building-Web-Applications-/Building-ASPNET-Web-Forms-Applications
|
|