How to use MVVM Light With Sql Server Compact

Mar 20, 2013 at 9:17 PM
I am using MVVM Light, Sql Server Compact Toolkit and windows phone 7.

I created a sql server compact 3.5 database and then used the toolkit to generate the datacontext and domain class for each table.

Looks like this

    [global::System.Data.Linq.Mapping.TableAttribute(Name = "ContactGroups")]
        public partial class ContactGroup : INotifyPropertyChanging, INotifyPropertyChanged
        {
    
            private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
    
            private int _Id;
    
            private string _Title;
    
            private System.DateTime _LastUpdated;
    
            private EntitySet<GContact> _GContacts;
    
            #region Extensibility Method Definitions
            partial void OnLoaded();
            partial void OnValidate(System.Data.Linq.ChangeAction action);
            partial void OnCreated();
            partial void OnIdChanging(int value);
            partial void OnIdChanged();
            partial void OnTitleChanging(string value);
            partial void OnTitleChanged();
            partial void OnLastUpdatedChanging(System.DateTime value);
            partial void OnLastUpdatedChanged();
            #endregion
    
            public ContactGroup()
            {
                this._GContacts = new EntitySet<GContact>(new Action<GContact>(this.attach_GContacts), new Action<GContact>(this.detach_GContacts));
                OnCreated();
            }
    
            [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Id", DbType = "Int NOT NULL", IsPrimaryKey = true)]
            public int Id
            {
                get
                {
                    return this._Id;
                }
                set
                {
                    if ((this._Id != value))
                    {
                        this.OnIdChanging(value);
                        this.SendPropertyChanging();
                        this._Id = value;
                        this.SendPropertyChanged("Id");
                        this.OnIdChanged();
                    }
                }
            }
    
            [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Title", DbType = "NVarChar(100) NOT NULL", CanBeNull = false)]
            public string Title
            {
                get
                {
                    return this._Title;
                }
                set
                {
                    if ((this._Title != value))
                    {
                        this.OnTitleChanging(value);
                        this.SendPropertyChanging();
                        this._Title = value;
                        this.SendPropertyChanged("Title");
                        this.OnTitleChanged();
                    }
                }
            }
    
            [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_LastUpdated", DbType = "DateTime NOT NULL")]
            public System.DateTime LastUpdated
            {
                get
                {
                    return this._LastUpdated;
                }
                set
                {
                    if ((this._LastUpdated != value))
                    {
                        this.OnLastUpdatedChanging(value);
                        this.SendPropertyChanging();
                        this._LastUpdated = value;
                        this.SendPropertyChanged("LastUpdated");
                        this.OnLastUpdatedChanged();
                    }
                }
            }
    
            [global::System.Data.Linq.Mapping.AssociationAttribute(Name = "FK_GContacts_ContactGroups", Storage = "_GContacts", ThisKey = "Id", OtherKey = "ContactGroups_Id", DeleteRule = "NO ACTION")]
            public EntitySet<GContact> GContacts
            {
                get
                {
                    return this._GContacts;
                }
                set
                {
                    this._GContacts.Assign(value);
                }
            }
    
            public event PropertyChangingEventHandler PropertyChanging;
    
            public event PropertyChangedEventHandler PropertyChanged;
    
            protected virtual void SendPropertyChanging()
            {
                if ((this.PropertyChanging != null))
                {
                    this.PropertyChanging(this, emptyChangingEventArgs);
                }
            }
    
            protected virtual void SendPropertyChanged(String propertyName)
            {
                if ((this.PropertyChanged != null))
                {
                    this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                }
            }
    
            private void attach_GContacts(GContact entity)
            {
                this.SendPropertyChanging();
                entity.ContactGroup = this;
            }
    
            private void detach_GContacts(GContact entity)
            {
                this.SendPropertyChanging();
                entity.ContactGroup = null;
            }
        }
Yet when I try to make it blendable(ie make fake data so when I go into blend I can work with it better instead of looking at empty boxes) nothing shows up in blend

when I have a simple domain without it works
      public class ContactGroup
        {
            public int Id { get; set; }
    
            public string Title { get; set; }
    
            public DateTime LastUpdated { get; set; }
    
            public List<GContacts> Contacts { get; set; }
    
            public ContactGroup()
            {
                Contacts = new List<GContacts>();
            }
    
        }
Then in my viewmodel locator I would have


        if (ViewModelBase.IsInDesignModeStatic)
        {
            SimpleIoc.Default.Register<IContactService, DesignContactService>();
        }
        else
        {
            SimpleIoc.Default.Register<IContactService, DesignContactService>();
        }
Mar 20, 2013 at 9:53 PM
Edited Mar 20, 2013 at 9:53 PM
The problem line seems to be

       private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
If I comment it out I get blendablity back. But not sure what to do with this line.
Apr 12, 2013 at 11:40 AM
chobo2, did you get this issue solved?
I too am facing the same issue and I have not found an answer yet