Print Page | Close Window

Querying during Save Interceptor?

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=3633
Printed Date: 13-May-2026 at 12:56am


Topic: Querying during Save Interceptor?
Posted By: stephenmcd1
Subject: Querying during Save Interceptor?
Date Posted: 18-Sep-2012 at 11:02am
We ran into some odd behavior in our custom Save Interceptor that I've tracked down to some DevForce logic that confuses me.  Some background:

We have a custom Save Interceptor that overrides ExecuteSave() and does some logic before and after we call base.ExecuteSave().  Often times we executes queries against the EntityManager.  We've noticed that if we execute a query before base.ExecuteSave(), then by the time base.ExecuteSave() finishes, the EntityManager will have its DefaultQueryStrategy set to CacheOnly.  That ends up messing with the queries we execute after base.ExecuteSave() since they never make it to the Data Source.  We could just force them to be DataSource only but that seems excessive and I'm wondering why the entity manager gets forced to Cache Only in the first place.

Tracing through a bit of the DevForce code, it seems that whenever an entity is added or removed from the Entity Manager during a Save (which happens when I query for an entity), the EntityServerSaveInterceptor sets WorkStateNeedsUpdate to true (which makes sense).  But then when UpdateWorkState is called, it ends up forcing the entity manager to Cache Only - which I don't understand (although, I wouldn't be surprised if there is a good reason).

Here is some sample code to illustrate our problem:
   public class TestSaveInterceptor : EntityServerSaveInterceptor
   {
        protected override bool ExecuteSave()
        {
            // These are two entity keys that we know will always exist in our DB. 
            // This is used as an example of one way we execute queries
            var keyThatExists1 = new EntityKey(typeof(Thing), 1);
            var keyThatExists2 = new EntityKey(typeof(Thing), 2);

            //If it's the 13th, load the first thing (yes, obviously not our actual code)
            if(DateTime.Today.Day == 13)
            {
                var thing1 = keyThatExists1.ToKeyQuery(EntityManager).Execute().Single();
            }

            //Do the normal save
            var result = base.ExecuteSave();
            
            //If it is a Friday, load the second thing
            if(DateTime.Today.DayOfWeek == DayOfWeek.Friday)
            {
                var thing2 = keyThatExists2.ToKeyQuery(EntityManager).Execute().Single();
            }

            //As long as it isn't Friday *and* the 13th, this code will run fine.  If only one of the queries runs,
            //  there are no problems.  It's just when they both run that the problem comes up since the first query
            //  causes the entity manager to be in CacheOnly which means the second query doesn't return any results
            //  (since thing 2 isn't in our cache) which then breaks the call to 'Single'.

            return result;
        }
    }

I'm not sure whether I'm just not supposed to be doing queries during save or maybe this is a bug.  Or maybe I should just clear out the Entity Manager's DefaultQueryStrategy after the call to base.ExecuteSave(), or ....

Thanks,
-Stephen



Replies:
Posted By: sbelini
Date Posted: 21-Sep-2012 at 1:00pm
Hi Stephen,
 
This problem has been fixed and will be available in our next release.
In the meantime, you should restore the DefatulQueryStrategy manually.
 
Regards,
   Silvio.


Posted By: stephenmcd1
Date Posted: 03-Oct-2012 at 3:07pm
Do you have an estimate for when the next release will be?  I know DF2012 is probably your main focus at the moment but we'll probably be on DF2010 for at least a little while and we'd want this issue fixed.


Posted By: sbelini
Date Posted: 03-Oct-2012 at 4:47pm
We are planning on having a DF2010 release late this month.
If you prefer, I can provide you with a patch.
Let me know.


Posted By: stephenmcd1
Date Posted: 04-Oct-2012 at 10:08am
A patch build would be nice.  We were hoping to get this fixed in the next 2 weeks.....and it sounds like the official release wouldn't be ready by then.


Posted By: stephenmcd1
Date Posted: 24-Oct-2012 at 10:34am
Originally posted by sbelini

We are planning on having a DF2010 release late this month.

Any updates on when the official version might be coming out?  It's getting close to the end of the month :-).

Thanks!


Posted By: sbelini
Date Posted: 25-Oct-2012 at 12:27pm
DevForce 2010 6.1.9 will be released within the next 2 weeks.



Print Page | Close Window