当前位置: 首页>>代码示例>>C#>>正文


C# DataServiceContext.Detach方法代码示例

本文整理汇总了C#中DataServiceContext.Detach方法的典型用法代码示例。如果您正苦于以下问题:C# DataServiceContext.Detach方法的具体用法?C# DataServiceContext.Detach怎么用?C# DataServiceContext.Detach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataServiceContext的用法示例。


在下文中一共展示了DataServiceContext.Detach方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplyToObject

        /// <summary>
        /// Applies this state to the specfied <paramref name="target"/> such that after invocation, 
        /// the target in the given <paramref name="context"/> is in this state.
        /// </summary>
        /// <param name="context">Context to apply changes to.</param>
        /// <param name="target">Target to change state on.</param>
        /// <param name="entitySetName">Name of entity set (necessary for certain transitions).</param>
        public void ApplyToObject(DataServiceContext context, object target, string entitySetName)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            EntityStates current = GetStateForEntity(context, target);
            if (current == this.state)
            {
                return;
            }

            switch (this.state)
            {
                case EntityStates.Added:
                    if (current != EntityStates.Detached)
                    {
                        context.Detach(target);
                    }

                    context.AddObject(entitySetName, target);
                    break;
                case EntityStates.Detached:
                    context.Detach(target);
                    break;
                case EntityStates.Deleted:
                    if (current == EntityStates.Detached)
                    {
                        context.AttachTo(entitySetName, target);
                    }

                    context.DeleteObject(target);
                    break;
                case EntityStates.Modified:
                    if (current == EntityStates.Detached)
                    {
                        context.AttachTo(entitySetName, target);
                    }

                    context.UpdateObject(target);
                    break;
                case EntityStates.Unchanged:
                    if (current != EntityStates.Detached)
                    {
                        context.Detach(target);
                    }

                    context.AttachTo(entitySetName, target);
                    break;
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:64,代码来源:EntityStateData.cs

示例2: AttachAndLog

        private static void AttachAndLog(StringBuilder output, DataServiceContext ctx, string entitySetName, object entity)
        {
            try
            {
                ctx.AttachTo(entitySetName, entity);

                EntityDescriptor entityDescriptor = ctx.Entities[0];
                entityDescriptor.Identity.Should().Be(entityDescriptor.EditLink.AbsoluteUri);
                output.AppendLine(entityDescriptor.EditLink.OriginalString);

                ctx.Detach(entity);
            }
            catch (Exception e)
            {
                var exception = e;
                while (exception != null)
                {
                    output.Append(exception.GetType().FullName);
                    output.Append(": ");
                    output.AppendLine(exception.Message);
                    exception = exception.InnerException;
                }
            }
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:24,代码来源:TemplatingIntegrationTests.cs

示例3: ClearContext

        public  static void ClearContext(DataServiceContext context)
        {
            Debug.Assert(context != null, "context != null");
            foreach (var link in context.Links)
            {
                context.DetachLink(link.Source, link.SourceProperty, link.Target);
            }

            foreach (var entity in context.Entities)
            {
                context.Detach(entity.Entity);
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:13,代码来源:DataServiceContextTests.cs


注:本文中的DataServiceContext.Detach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。