Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3633638
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:40:42+00:00 2026-05-19T00:40:42+00:00

So I’ve got an odd bug I’m hoping someone can help me with. I

  • 0

So I’ve got an odd bug I’m hoping someone can help me with.

I have the following code to grab some entities from WCF RIA Services, this is in Silverlight 4, though my guess is that doesn’t make a difference.

What am I missing?

public class MyModel
{
    ...

    public IEnumerable<MyEntity> Result { get; private set; }

    public void Execute()
    {
        Context.Load(Query, LoadBehavior.RefreshCurrent, o =>
        {
            if (o.HasError)
            {
                ExecuteException = o.Error;
                if (ExecuteError != null)
                    ExecuteError(this, EventArgs.Empty);
                o.MarkErrorAsHandled();
            }
            else
            {
                //I've stepped through the code and the assignment is working
                //Result != null
                Result = o.Entities; 
                if (ExecuteSuccess != null)
                    ExecuteSuccess(this, EventArgs.Empty);
                //Inside any Handler of ExecuteSuccess
                //MyModel.Result == null
                //However I set a break point after ExecuteSuccess is triggered,
                //and once again MyModel.Result != null

            }

            if (ExecuteComplete != null)
                ExecuteComplete(this, EventArgs.Empty);

            ExecuteBusy = false;

        }, false);
    }
}

Everything works until I get to this point:

MyModel.ExecuteSuccess += (o,e) => {
    //At this point MyModel.Result == null.  but why?
    var result = MyModel.Result;
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:40:42+00:00Added an answer on May 19, 2026 at 12:40 am

    Yeah I found the issue I was doing some crazy stuff in order to make MVVM + RIA Services more fun, in an inheriting class I was casting MyModel.Result to MyModel.Result as IEnumerable<TEntity>; which doesn’t work. I used MyModel.Result.OfType<TEntity> instead. I’m posting all the code in case it’s useful to someone else.

    public abstract class RiaQuery : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged values
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    
        #region Query
    
        private EntityQuery _Query;
    
        public EntityQuery Query
        {
            get { return _Query; }
            private set
            {
                if (_Query != value)
                {
                    _Query = value;
                    RaisePropertyChanged("Query");
                }
            }
        }
    
        #endregion
    
        #region Result
    
        private IEnumerable _Result;
    
        public IEnumerable Result
        {
            get { return _Result; }
            private set
            {
                if (_Result != value)
                {
                    _Result = value;
                    RaisePropertyChanged("Result");
                }
            }
        }
    
        #endregion
    
        #region ExecuteBusy
    
        private bool _ExecuteBusy;
    
        public bool ExecuteBusy
        {
            get { return _ExecuteBusy; }
            private set
            {
                if (_ExecuteBusy != value)
                {
                    _ExecuteBusy = value;
                    RaisePropertyChanged("ExecuteBusy");
                }
            }
        }
    
        #endregion
    
        #region ExecuteCommand
    
        private DelegateCommand _ExecuteCommand;
    
        public DelegateCommand ExecuteCommand
        {
            get
            {
                if (_ExecuteCommand == null)
                {
                    _ExecuteCommand = new DelegateCommand(o => Execute(o), o => !ExecuteBusy);
                }
                return _ExecuteCommand;
            }
        }
    
        #endregion
    
        #region ExecuteException
    
        private Exception _ExecuteException;
    
        public Exception ExecuteException
        {
            get { return _ExecuteException; }
            private set
            {
                if (_ExecuteException != value)
                {
                    _ExecuteException = value;
                    RaisePropertyChanged("ExecuteException");
                }
            }
        }
    
        #endregion
    
        public event EventHandler ExecuteBegin;
        public event EventHandler ExecuteComplete;
        public event EventHandler ExecuteSuccess;
        public event EventHandler ExecuteError;
    
        protected  DomainContext Context;
    
        public bool CreateQueryEachTime { get; set; }
    
        public RiaQuery(DomainContext context)
        {
            if (context == null) throw new ArgumentException("context");
            Context = context;
        }
    
        public void Execute(object param)
        {
            ExecuteBusy = true;
    
            if (ExecuteBegin != null)
                ExecuteBegin(this, EventArgs.Empty);
    
            if (CreateQueryEachTime || Query == null)
                CreateQueryInternal();
    
            Context.Load(Query, LoadBehavior.RefreshCurrent, o =>
            {
                if (o.HasError)
                {
                    ExecuteException = o.Error;
                    if (ExecuteError != null)
                        ExecuteError(this, EventArgs.Empty);
                    o.MarkErrorAsHandled();
                }
                else
                {
                    Result = o.Entities;
                    if (ExecuteSuccess != null)
                        ExecuteSuccess(this, EventArgs.Empty);
                }
    
                if (ExecuteComplete != null)
                    ExecuteComplete(this, EventArgs.Empty);
    
                ExecuteBusy = false;
    
            }, false);
        }
    
        private void CreateQueryInternal()
        {
            Query = CreateQuery();
        }
    
        protected abstract EntityQuery CreateQuery();
    }
    
    public abstract class RiaQuery<TContext> : RiaQuery
        where TContext : DomainContext
    {
        new protected TContext Context
        {
            get { return base.Context as TContext; }
            set { base.Context = value; }
        }
    
        public RiaQuery(TContext context) : base(context) { }
    }
    
    public abstract class RiaQuery<TContext,TEntity> : RiaQuery<TContext>
        where TContext : DomainContext
        where TEntity : Entity 
    {
        new public EntityQuery<TEntity> Query
        {
            get { return base.Query as EntityQuery<TEntity>; }
        }
    
        new public IEnumerable<TEntity> Result
        {
            get { return base.Result.OfType<TEntity>(); }
        }
    
        public RiaQuery(TContext context) : base(context) { }
    }
    
    public class DelegateRiaQuery<TContext> : RiaQuery<TContext>
        where TContext : DomainContext
    {
        protected Func<TContext, EntityQuery> CreateQueryDelegate;
    
        public DelegateRiaQuery(TContext context, Func<TContext, EntityQuery> createQueryDelegate)
            : base(context)
        {
            if (createQueryDelegate == null) throw new ArgumentException("createQueryDelegate");
            CreateQueryDelegate = createQueryDelegate;
        }
    
        protected override EntityQuery CreateQuery()
        {
            return CreateQueryDelegate(Context);
        }
    }
    
    public class DelegateRiaQuery<TContext, TEntity> : RiaQuery<TContext, TEntity> 
        where TContext : DomainContext 
        where TEntity : Entity
    {
        protected Func<TContext, EntityQuery<TEntity>> CreateQueryDelegate;
    
        public DelegateRiaQuery(TContext context, Func<TContext, EntityQuery<TEntity>> createQueryDelegate) : base(context)
        {
            if (createQueryDelegate == null) throw new ArgumentException("createQueryDelegate");
            CreateQueryDelegate = createQueryDelegate;
        }
    
        protected override EntityQuery CreateQuery()
        {
            return CreateQueryDelegate(Context);
        }
    }
    

    Usage looks like this:

    public class MyModel : INotifyPropertyChanged
    {
        ...
    
        public DelegateRiaQuery<MyContxt,MyEntity> MyModelOperation { get; private set; }
    
        public MyModel()
        {
            var context = new MyContext();
            MyModelOperation = new DelegateRiaQuery(context, c => c.GetMyModelEntitiesQuery(this.Property1));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have a bunch of posts stored in text files formatted in yaml/textile (from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.