ArgumentException getting LazyValue.Value

Feb 3, 2011 at 9:17 PM

I am trying to retrieve an object that I have previously saved but am getting an ArgumentException when trying to retrieve the Value, my classes are as follows:

   public class PostsViewModel : ViewModelBase
    {

        #region Properties

        private ObservableCollection<PostViewModel> _posts;
        private bool _isDirty;
        private bool _isLoading = false;
        private PostsType _postListType;

        public ObservableCollection<PostViewModel> Posts
        {
            get
            {
                return _posts;
            }
            set
            {
                if (_posts != value)
                {
                    _posts = value;
                    RaisePropertyChanged(() => Posts);
                }
            }
        }

        public bool IsDirty
        {
            get { return _isDirty; }
            set
            {
                if (value != _isDirty)
                {
                    _isDirty = value;
                    RaisePropertyChanged(() => IsDirty);
                }
            }
        }

        public bool IsLoading
        {
            get { return _isLoading; }
            set
            {
                if (_isLoading != value)
                {
                    _isLoading = value;
                    Messenger.Default.Send<bool>(_isLoading, "IsLoading");
                    RaisePropertyChanged(() => IsLoading);
                }
            }
        }

        public PostsType PostListType
        {
            get { return _postListType; }
            set
            {
                if (value != _postListType)
                {
                    _postListType = value;
                    RaisePropertyChanged(() => PostListType);
                }
            }
        }

        private bool _dataLoaded = false;
        public bool DataLoaded
        {
            get { return _dataLoaded; }
            set
            {
                if (value != _dataLoaded)
                {
                    _dataLoaded = value;
                    RaisePropertyChanged(() => DataLoaded);
                }
            }
        }

        #endregion
	// Methods not pasted for save of brevity!
}
 
    public class PostViewModel : ViewModelBase
    {
        private string _Href;
        private string _Description;
        private string _Hash;
        private string _Tag;
        private string _Time;
        private string _Extended;
        private bool _Shared;
        private DateTime _dateUpdated;
        private bool _isDirty;

        #region Properties

        /// <summary>
        /// Get/Set the Href for this <c>Post</c>
        /// </summary>
        public string Href
        {
            get { return this._Href; }
            set 
            { 
                if (value != _Href)
                {
                    this._Href = value
                    RaisePropertyChanged(() => Href);
                }
            }
        }

        /// <summary>
        /// Get/Set the Description of this <c>Post</c>
        /// </summary>
        public string Description
        {
            get { return this._Description; }
            set 
            { 
                if (value != _Description)
                {
                    this._Description = value
                    RaisePropertyChanged(() => Description);
                }
            }
        }

        /// <summary>
        /// Get/Set the Hash for this <c>Post</c>
        /// </summary>
        public string Hash
        {
            get { return this._Hash; }
            set 
            { 
                if (value != _Hash)
                {
                    this._Hash = value
                    RaisePropertyChanged(() => Hash);
                }
            }
        }

        /// <summary>
        /// Get/Set the Tag for this <c>Post</c>
        /// </summary>
        public string Tag
        {
            get { return this._Tag; }
            set 
            { 
                if (value != _Tag)
                {
                    this._Tag = value
                    RaisePropertyChanged(() => Tag);
                    RaisePropertyChanged(() => Tags);
                }
            }
        }

        /// <summary>
        /// Get an array of strings containing each Tag for this <c>Post</c>
        /// </summary>
        public string[] Tags
        {
            get
            {
                if (this.Tag == null || this.Tag.Length == 0)
                    return null;
                return this.Tag.Split(' ');
            }
        }

        /// <summary>
        /// Get/Set the Time of this <c>Post</c>
        /// </summary>
        public string Time
        {
            get { return this._Time; }
            set 
            { 
                if (value != _Time)
                {
                    this._Time = value
                    RaisePropertyChanged(() => Time);
                }
            }
        }

        /// <summary>
        /// Get/Set the Extended properties for this <c>Post</c>
        /// </summary>
        public string Extended
        {
            get { return this._Extended; }
            set
            { 
                if (value != _Extended)
                {
                    this._Extended = value
                    RaisePropertyChanged(() => Extended);
                }
            }
        }

        /// <summary>
        /// Get/Set the Shared bit for this <c>Post</c>
        /// </summary>
        public bool Shared
        {
            get { return this._Shared; }
            set 
            { 
                if (value != _Shared)
                {
                    this._Shared = value
                    RaisePropertyChanged(() => Shared);
                }
            }
        }

        public DateTime DateUpdated
        {
            get { return _dateUpdated; }
            set
            {
                if (value != _dateUpdated)
                {
                    this._dateUpdated = value;
                    RaisePropertyChanged(() => DateUpdated);
                }
            }
        }

        public bool IsDirty
        {
            get { return _isDirty; }
            set
            {
                if (value != _isDirty)
                {
                    this._isDirty = value;
                    RaisePropertyChanged(() => IsDirty);
                }
            }
        }

        #endregion

        public PostViewModel()
        {
            this._isDirty = false;
            this._dateUpdated = DateTime.MinValue;
        }

        public PostViewModel(Post post) : this()
        {
            this._Href = post.Href;
            this._Description = post.Description;
            this._Hash = post.Hash;
            this._Tag = post.Tag;
            this._Time = post.Time;
            this._Extended = post.Extended;
            this._Shared = post.Shared;
        }
        
    }
 
######
 
            foreach (PostsViewModel p in StaticPosts.Values.ToList())
            {
                if (!p.Persisted)
                {
                    p.Persisted = true;
                    var key = App.Database.Save<PostsViewModel>(p);
                }
            }
#######
Loading I have tried 
App.Database.Load<PostsViewModel>(postsType.ToString())
and also the code from the example project :
            if (hasKeys)
            {
                foreach (var item in DeliciousDB.Database.Query<PostsViewModelstring>()).

                {
                    PostsViewModel postsVM = item.LazyValue.Value;
                    this.PostsDictionary[postsVM.PostListType.ToString()].Load(postsVM);
                }
            }
also tried it without the Where clause but to no avail, can anyone give me a pointer as to what I could be doing wrong?  I am using the same code to save & 
load a simpler class with no problem.
Thanks,
Rupert.
Where(p => p.Key == postsType.ToString()))