Пример #1
0
        private _ServiceSearchParameter UpdateServiceSearchParameters(int Id, _ServiceSearchParameter SearchParameter)
        {
            var DbSearchParameter = IPyroDbContext.ServiceSearchParameter.SingleOrDefault(x => x.Id == Id);

            DbSearchParameter.Description = SearchParameter.Description;
            DbSearchParameter.Expression  = SearchParameter.Expression;
            DbSearchParameter.IsIndexed   = SearchParameter.IsIndexed;
            DbSearchParameter.LastUpdated = DateTimeOffset.Now;
            DbSearchParameter.Name        = SearchParameter.Name;
            DbSearchParameter.Resource    = SearchParameter.Resource;
            DbSearchParameter.SearchParameterResourceId      = SearchParameter.SearchParameterResourceId;
            DbSearchParameter.SearchParameterResourceVersion = SearchParameter.SearchParameterResourceVersion;
            DbSearchParameter.Status = SearchParameter.Status;
            DbSearchParameter.TargetResourceTypeList = SearchParameter.TargetResourceTypeList;
            DbSearchParameter.Type  = SearchParameter.Type;
            DbSearchParameter.Url   = SearchParameter.Url;
            DbSearchParameter.XPath = SearchParameter.XPath;
            IPyroDbContext.Entry(DbSearchParameter).State = EntityState.Modified;
            this.Save();
            return(DbSearchParameter);
        }
        private _ServiceSearchParameter UpdateServiceSearchParameters(int Id, _ServiceSearchParameter SearchParameter)
        {
            var DbSearchParameter = IPyroDbContext.ServiceSearchParameter
                                    .Include(x => x.TargetResourceTypeList)
                                    .Include(x => x.ServiceSearchParameterCompositePivotList)
                                    .SingleOrDefault(x => x.Id == Id);

            //We must tell EF to delete each child element not just assign the new list.
            //We could try and work out the difference between the two lists and only Add, Update and Remove as required
            //Yet given this is a very infrequent process with very small numbers it is just easier to delete all
            // and add the entire new list.
            for (int i = DbSearchParameter.TargetResourceTypeList.Count - 1; i >= 0; i--)
            {
                (IPyroDbContext as IObjectContextAdapter).ObjectContext.DeleteObject(DbSearchParameter.TargetResourceTypeList.ElementAt(i));
            }

            for (int i = DbSearchParameter.ServiceSearchParameterCompositePivotList.Count - 1; i >= 0; i--)
            {
                (IPyroDbContext as IObjectContextAdapter).ObjectContext.DeleteObject(DbSearchParameter.ServiceSearchParameterCompositePivotList.ElementAt(i));
            }

            DbSearchParameter.Description = SearchParameter.Description;
            DbSearchParameter.Expression  = SearchParameter.Expression;
            DbSearchParameter.IsIndexed   = SearchParameter.IsIndexed;
            DbSearchParameter.LastUpdated = DateTimeOffset.Now;
            DbSearchParameter.Name        = SearchParameter.Name;
            DbSearchParameter.Resource    = SearchParameter.Resource;
            DbSearchParameter.SearchParameterResourceId      = SearchParameter.SearchParameterResourceId;
            DbSearchParameter.SearchParameterResourceVersion = SearchParameter.SearchParameterResourceVersion;
            DbSearchParameter.Status = SearchParameter.Status;
            DbSearchParameter.TargetResourceTypeList = SearchParameter.TargetResourceTypeList;
            DbSearchParameter.ServiceSearchParameterCompositePivotList = SearchParameter.ServiceSearchParameterCompositePivotList;
            DbSearchParameter.Type  = SearchParameter.Type;
            DbSearchParameter.Url   = SearchParameter.Url;
            DbSearchParameter.XPath = SearchParameter.XPath;
            IPyroDbContext.Entry(DbSearchParameter).State = EntityState.Modified;
            this.Save();
            return(DbSearchParameter);
        }