New Posts New Posts RSS Feed: Changes to property using Property Interceptors not persisted to database
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Changes to property using Property Interceptors not persisted to database

 Post Reply Post Reply
Author
Lee_H View Drop Down
Newbie
Newbie
Avatar

Joined: 27-Jul-2010
Location: Solomon Islands
Posts: 3
Post Options Post Options   Quote Lee_H Quote  Post ReplyReply Direct Link To This Post Topic: Changes to property using Property Interceptors not persisted to database
    Posted: 28-Jul-2010 at 6:46pm
Below is the interceptor code. It is fairly ordinary.

The method TranslatePrefixtoRegEx mangles the property PrefixList and generates a default RegEx from it (it returns it as a string). Which is what I want to happen if PrefixRegEx happens to be null or empty.

#region Property Interceptors
[AfterGet(EntityPropertyNames.PrefixRegEx)]
public void PrefixRegExAfterGet (PropertyInterceptorArgs<StateRegionSub, string> args)
{
    var prefixRegEx = args.Value;

    if (String.IsNullOrWhiteSpace(prefixRegEx))
    {
        if (prefixRegEx == null)
            prefixRegEx = "";

        if (!String.IsNullOrWhiteSpace(PrefixList))
        {
            args.Value = TranslatePrefixToRegEx(PrefixList);
        }
    }
}

[BeforeSet(EntityPropertyNames.PrefixRegEx)]
public void PrefixRegExBeforeSet(PropertyInterceptorArgs<StateRegionSub, string> args)
{
    var prefixRegEx = args.Value;

    if (String.IsNullOrWhiteSpace(prefixRegEx))
    {
        if (prefixRegEx == null)
        {
            prefixRegEx = "";
        }

        if (!String.IsNullOrWhiteSpace(PrefixList))
        {
            args.Value = TranslatePrefixToRegEx(PrefixList);
        }
    }
}
#endregion
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 28-Jul-2010 at 5:39pm
The only two things I can think of are:

  1. The value is getting changed in the datagrid cell but not in the business object

  2. The value is somehow getting set back to its original value before the save


But since I imagine your AfterGet makes the change directly in the business object, and knows nothing about the grid, possibility #1 seems ruled out. I didn't list the possibilitity that the entity is never flagged as modified and so isn't saved, because you've indicated that you've changed (and successfully saved) other properties of the same entity simultaneously. That leaves listed possibility #2, which seems remote as well. But perhaps should list your AfterGet and BeforeSet code.
Back to Top
Lee_H View Drop Down
Newbie
Newbie
Avatar

Joined: 27-Jul-2010
Location: Solomon Islands
Posts: 3
Post Options Post Options   Quote Lee_H Quote  Post ReplyReply Direct Link To This Post Posted: 27-Jul-2010 at 10:24pm
Update:
I've regenerated the EDM from the database (the database had not changed), and I've also changed the query to not be so eager.  The entity in question was the 'child' entity.  It looks like some deeply buried metadata had gotten slightly scrambled.
 
So now it will persist the changes to the property itself where I edit them, but it still won't persist the generated default value.  So my question with regard to AfterGet and BeforeSet still stands.
Back to Top
Lee_H View Drop Down
Newbie
Newbie
Avatar

Joined: 27-Jul-2010
Location: Solomon Islands
Posts: 3
Post Options Post Options   Quote Lee_H Quote  Post ReplyReply Direct Link To This Post Posted: 27-Jul-2010 at 6:10pm
My apologies if this is a newb question.  If so please point me at the relevant URL.
 
Version: Devforce Silverlight v6.0.3.1
 
I have an entity that has a property that, if empty, needs to be populated with a default value that can be generated from one of the other properties.  To do that I have both an AfterGet and BeforeSet defined for it.
 
In my Silverlight app I can see the default value in the DataGrid, so I can tell that the AfterGet is working.  However, this value is not being persisted back to the datastore.  If I manually edit this value (or change one of the other properties in the row) so that the RwoEditEnded event is fired, even then the value does not get persisted, although any other value that I've edited does.
 
What am I missing?
 
Do I need to 'dirty' the property in some way?
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down