Print Page | Close Window

Changes to property using Property Interceptors not persisted to database

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2016
Printed Date: 25-Mar-2025 at 8:42pm


Topic: Changes to property using Property Interceptors not persisted to database
Posted By: Lee_H
Subject: Changes to property using Property Interceptors not persisted to database
Date 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?



Replies:
Posted By: Lee_H
Date 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.


Posted By: GregD
Date 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.


Posted By: Lee_H
Date 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



Print Page | Close Window