Windows Phone 8 - Linq to SQL (SQL CE) - Associations with vmprop

Topics: Feature requests, Questions
Aug 13, 2013 at 8:43 PM
Hi,

is there any way to make the vmporp snippet work for Linq to SQL Associations?
Here is my Association
#region Workplace property
        private EntityRef<Workplace> _workplaceRef;

        [Association(Name = "FK_Workplace_Computers", Storage = "_workplaceRef", ThisKey = "WorkplaceId", OtherKey = "Id", IsForeignKey = true)]
        public Workplace Workplace
        {
            get { return _workplaceRef.Entity; }
            set
            {
                Workplace previousValue = _workplaceRef.Entity;
                if (previousValue != value || !_workplaceRef.HasLoadedOrAssignedValue)
                {
                    RaisePropertyChanging(() => Workplace);
                    if (previousValue != null)
                    {
                        _workplaceRef.Entity = null;
                        previousValue.Computers.Remove(this);
                    }
                    _workplaceRef.Entity = value;
                    if (value != null)
                    {
                        value.Computers.Add(this);
                        _workplaceId = value.Id;
                    }
                    else
                    {
                        _workplaceId = default(Guid?);
                    }
                    RaisePropertyChanging(() => Workplace);
                }
            }
        }
        #endregion
Aug 13, 2013 at 8:48 PM
or does it even make sense to use to vmprop here?
Coordinator
Aug 14, 2013 at 9:11 AM
It has no use to use vmprop here. The question is: do you want this logic in your VM setter or is this actually a model / service part? I don't like logic in setters, but that is just my personal preference.