コード例 #1
0
        protected override void UpdateDataObject(object dataContext, object table, object oldDataObject, object newDataObject)
        {
            var    dataServiceContext  = (DataServiceContext)dataContext;
            var    idataServiceContext = dataContext as IDataServiceContext;
            string etag = null;

            if (this._etagMap != null && this._etagMap.TryGetValue(DataServiceUtilities.BuildCompositeKey(oldDataObject), out etag))
            {
                if (idataServiceContext != null)
                {
                    idataServiceContext.AttachTo(TableName, newDataObject, etag);
                }
                else
                {
                    dataServiceContext.AttachTo(TableName, newDataObject, etag);
                }
            }
            else
            {
                if (idataServiceContext != null)
                {
                    idataServiceContext.AttachTo(TableName, newDataObject);
                }
                else
                {
                    dataServiceContext.AttachTo(TableName, newDataObject);
                }
            }

            ProcessForeignKeys(dataServiceContext, newDataObject, _values);

            dataServiceContext.UpdateObject(newDataObject);
            DataServiceResponse dataServiceResponse = dataServiceContext.SaveChanges();
        }
コード例 #2
0
        protected override void DeleteDataObject(object dataContext, object table, object oldDataObject)
        {
            var    dataServiceContext  = (DataServiceContext)dataContext;
            var    idataServiceContext = dataContext as IDataServiceContext;
            string etag = null;

            if (this._etagMap != null && this._etagMap.TryGetValue(DataServiceUtilities.BuildCompositeKey(oldDataObject), out etag))
            {
                if (idataServiceContext != null)
                {
                    idataServiceContext.AttachTo(TableName, oldDataObject, etag);
                }
                else
                {
                    dataServiceContext.AttachTo(TableName, oldDataObject, etag);
                }
            }
            else
            {
                if (idataServiceContext != null)
                {
                    idataServiceContext.AttachTo(TableName, oldDataObject);
                }
                else
                {
                    dataServiceContext.AttachTo(TableName, oldDataObject);
                }
            }
            dataServiceContext.DeleteObject(oldDataObject);
            dataServiceContext.SaveChanges();
        }
コード例 #3
0
        protected override object SaveViewState()
        {
            var myState = new Pair();

            myState.First = base.SaveViewState();
            if (_dataServiceContext != null)
            {
                myState.Second = _dataServiceContext.Entities.Where(ed => !String.IsNullOrEmpty(ed.ETag)).ToDictionary(
                    ed => DataServiceUtilities.BuildCompositeKey(ed.Entity), ed => ed.ETag);
            }
            return(myState);
        }