Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Modify an entity from LLBLGenProDataSource2.EntityCollection during callback
 

Pages: 1
LLBLGen Pro Runtime Framework
Modify an entity from LLBLGenProDataSource2.EntityCollection during callback
Page:1/1 

  Print all messages in this thread  
Poster Message
JimFoye
User



Location:
Austin, TX
Joined on:
22-Jun-2004 04:03:11
Posted:
656 posts
# Posted on: 09-Feb-2009 05:34:05.  
I want to manually modify an entity during a callback. It seems to work, but there is a bit of weirdness at the end.

I'm using a Developer Express ASPxDataView control, and inside of it is an ASPxRadioButtonList. When the user changes the selection in the latter, I force a callback, so I can change the associated field in the entity. Here's the callback handler:

Code:

        protected void uiDataView_CustomCallback(object source, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            LocationEntity location = (LocationEntity)locationsDS.EntityCollection[uiDataView.PageIndex];
            // new status code will be SelectedIndex + 1
            location.LocationStatusID = int.Parse(e.Parameter) + 1;
            // debugging: little easier to see if I have the changed entity
            location.DBA = location.DBA + " (CHANGED)";
            manager.Save(location);
            // debugging: location indeed has the new values for [DBA] and [LocationStatusID]
            location = (LocationEntity)locationsDS.EntityCollection[uiDataView.PageIndex];
        }


This works, the entity is the correct one, and I've confirmed the changes are saved to the database. However, later when I page back to this entity, it appears that an older copy of the entity is still hanging around. Below is my method GetSelectedIndex() which is called by the radio button list control to determine what SelectedIndex should be.

Code:

        protected int GetSelectedIndex()
        {
            LocationEntity location = (LocationEntity)locationsDS.EntityCollection[uiDataView.PageIndex];
            // debugging: this location has the old values for [DBA] and [LocationStatusID]!
            return location.LocationStatusID - 1;
        }


The entity I get here from locationsDS.EntityCollection, using the same index (believe me, I'm making sure!) has the old values for the fields, not what's currently in the database. If I refresh the page, I see the new values.

I've tried doing various things, like setting locationsDS.Refetch to true, followed by Databind() on the control, etc., but nothing works.



  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14549 posts
# Posted on: 09-Feb-2009 09:41:45.  
Quote:
// debugging: location indeed has the new values for [DBA] and [LocationStatusID]
            location = (LocationEntity)locationsDS.EntityCollection[uiDataView.PageIndex];


At the end of the uiDataView_CustomCallback() what are the values of the following:

location.Fields["DBA"].IsChanged
location.Fields["DBA"].CurrentValue
location.Fields["DBA"].DBValue
location.Fields.State
location.IsDirty

I guess you might need to refetch the entoty after Saving it.


  Top
JimFoye
User



Location:
Austin, TX
Joined on:
22-Jun-2004 04:03:11
Posted:
656 posts
# Posted on: 09-Feb-2009 16:27:46.  
Walaa,

I should have added, my save does refetch, here is the code for that:
Code:

        public void Save(EntityBase2 entity)
        {
            DataAccessAdapter adapter = new DataAccessAdapter();
            adapter.SaveEntity(entity, true);
        }


And here is the other information you requested:

location.Fields["DBA"].IsChanged = false
location.Fields["DBA"].CurrentValue = "EBS (CHANGED)"
location.Fields["DBA"].DbValue = "EBS (CHANGED)"
location.Fields.State = Fetched
location.IsDirty = false

  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14549 posts
# Posted on: 10-Feb-2009 08:06:55.  
All looks good.
Would you please try to re-set the datasource of the grid and then call DataBind()?
This should refresh the bound Default EntityView.



  Top
JimFoye
User



Location:
Austin, TX
Joined on:
22-Jun-2004 04:03:11
Posted:
656 posts
# Posted on: 12-Feb-2009 20:20:58.  
Added this after saving the entity:

Code:
    
            uiDataView.DataSourceID = String.Empty;
            uiDataView.DataSourceID = "locationsDS";
            uiDataView.DataBind();


but it didn't help. It's not a grid, btw, it's the Developer Express equivalent of a DataView. I don't think it's a control problem, though. Again, it's very baffling that the LocationEntity at that index in locationsDS.EntityCollection appears to be the saved (and refetched) entity with the new values, and then a little later in the same callback I retrieve what I think is the same entity, but that entity has the old values.
  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14549 posts
# Posted on: 13-Feb-2009 09:33:11.  
Could you please try the following code:
Code:
uiDataView.DataSource = locationsDS;
uiDataView.DataBind();



  Top
JimFoye
User



Location:
Austin, TX
Joined on:
22-Jun-2004 04:03:11
Posted:
656 posts
# Posted on: 13-Feb-2009 18:22:23.  
No difference.
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37694 posts
# Posted on: 13-Feb-2009 18:54:07.  
Could you check if the ObjectID (which is a GUID) is the same for both entity instances (so the one with the new values which is at the correct index and the one which appears to have the old values) ?

Also, what's the cache location for the DS' data? Cache, session or viewstate?


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
JimFoye
User



Location:
Austin, TX
Joined on:
22-Jun-2004 04:03:11
Posted:
656 posts
# Posted on: 18-Feb-2009 20:23:44.  
Frans, sorry I took so long to reply.

The ObjectID does change:

Code:

initial call to GetSelectedIndex():        {bd7d1af2-fb26-4cf9-888f-26de7fb9f688}
start of callback:                                 {bd7d1af2-fb26-4cf9-888f-26de7fb9f688}
after save, still in callback:                 {bd7d1af2-fb26-4cf9-888f-26de7fb9f688}
move off, return, GetSelectedIndex(): {55435a75-8141-440f-add5-604adc81d3e5}


This is true whether or not I reset DataSource and call DataBind() in the callback handler.

CacheLocation is ViewState. So, let me try changing that...

[5 minutes later]

I changed it to Session, and it works! No need to reset DataSource and call DataBind(), either. I change the value, save (with refetch) during the callback. When I move off and return to that record, my GetSelectedIndex() now finds the correct new values. This is what I expected all along.

So, I'm guessing the old values are still in the viewstate, and this the entity is getting reconstituted from that?

This reminds me, I had another page where the dataset was reaching about 5000 records, and I started getting errors because the HTTP request was getting too big, and changing the CacheLocation to Session solved the problem. But CacheLocation defaults to ViewState, I wonder how often some app is just humming along and then this happens because the data gets too big.

Jim
  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14549 posts
# Posted on: 19-Feb-2009 09:48:59.  
Thanks for the feedback.

  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.