/// <summary>
        /// Merges model collection properties. May be used in cases where DbContextReflector is unable to identify all collection properties
        /// </summary>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="entity">Entity in the context</param>
        /// <param name="model">Model that contains changes</param>
        /// <param name="modelProperty"></param>
        /// <param name="actionOnDelete"></param>
        /// <param name="referencedEntityIsDependent"></param>
        protected void MergeCollectionProperty <TProperty>(TModel entity, TModel model, Expression <Func <TModel, IList <TProperty> > > modelProperty,
                                                           System.Data.Entity.Core.Metadata.Edm.OperationAction actionOnDelete, bool referencedEntityIsDependent)
            where TProperty : class
        {
            MemberExpression       mex          = (MemberExpression)modelProperty.Body;
            PropertyInfo           property     = (PropertyInfo)mex.Member;
            NavigationPropertyInfo propertyInfo = new NavigationPropertyInfo(property, actionOnDelete, referencedEntityIsDependent);

            ICollectionPropertyUpdater <TModel> collectionPropertyUpdater = new CollectionPropertyUpdater <TModel>(DbContext, entity, collectionMerger);

            collectionPropertyUpdater.UpdateCollection <TProperty>(reflector, propertyInfo, model, entity == model, navUpdater);
        }
Exemple #2
0
        /*public void UpdateCollection(Expression<Func<TModel, IList<TCollectionEntry>>> property, object sourceModel)
         * {
         *  MemberExpression mex = (MemberExpression)property.Body;
         *  UpdateCollection((PropertyInfo)mex.Member, sourceModel);
         * }*/

        public void UpdateCollection <TCollectionEntry>(IDbContextReflector reflector, NavigationPropertyInfo property,
                                                        object sourceModel, bool modelIsNew, IRecursiveEntityUpdater entityUpdater)
            where TCollectionEntry : class
        {
            Reflector     = reflector;
            Property      = property;
            EntityUpdater = entityUpdater;

            if (modelIsNew)
            {
                AddCollection((IList <TCollectionEntry>)property.PropertyInfo.GetValue(sourceModel));
            }
            else
            {
                UpdateCollection((IList <TCollectionEntry>)property.PropertyInfo.GetValue(Model),
                                 (IList <TCollectionEntry>)property.PropertyInfo.GetValue(sourceModel));
            }
        }
Exemple #3
0
 private void SetEntityReferenceToNullOnTargetResourceMatch(object targetResource, NavigationPropertyInfo navigationPropertyInfo, object currentEntityInstance)
 {
     if (navigationPropertyInfo.PropertyInfo.GetValue(currentEntityInstance, null) == targetResource)
     {
         this.pendingChanges.Add(delegate {
             navigationPropertyInfo.PropertyInfo.SetValue(currentEntityInstance, null, null);
         });
     }
 }
Exemple #4
0
        private void RemoveResourceFromCollectionOnTargetResourceMatch(object targetResource, NavigationPropertyInfo navigationPropertyInfo, object currentEntityInstance)
        {
            IEnumerable childCollectionObject = navigationPropertyInfo.PropertyInfo.GetValue(currentEntityInstance, null) as IEnumerable;

            if (childCollectionObject.Cast <object>().Any <object>(delegate(object o) {
                return(o == targetResource);
            }))
            {
                MethodInfo removeMethod = navigationPropertyInfo.PropertyInfo.PropertyType.GetMethod("Remove");
                this.pendingChanges.Add(delegate {
                    removeMethod.Invoke(childCollectionObject, new object[] { targetResource });
                });
            }
        }