本文整理汇总了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;
}
}
示例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;
}
}
}
示例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);
}
}