zoukankan      html  css  js  c++  java
  • Cannot remove an entity that has not been attached

    [TestMethod()]
    //[ExpectedException(typeof(System.ArgumentNullException))]
    public void DeleteTest()
    {
        Ervice target = new Ervice (con);
        Guid erviceID = new Guid("{C49ACB94-F51F-45FF-8D1B-5FBBC9BC3C00}");
        target.Delete(erviceID );
    }

    异常:

    Test method TestProjectCategoryEnum.EmbankmentAreaServiceTest.DeleteTest threw exception:  System.InvalidOperationException: Cannot remove an entity that has not been attached..

    MSDN:

    可对一些实体使用 Attach 方法。这些实体在一个 DataContext 中创建并序列化到客户端,随后被反序列化回来,以便执行更新或删除操作。

    Table<(Of <(TEntity>)>)..::.Attach 方法

    将实体附加到 DataContext

    var l = this.ReadonlyDataContext.Es.Single(p => p.EmbankmentID == embankmentID);
    this.Es.EmbankmentAreas.Attach(l);
    this.Es.EmbankmentAreas.DeleteOnSubmit(l);
    this.Es.SubmitChanges();

  • 相关阅读:
    Codeforces Round #274 (Div. 2)
    codeforces 477C
    ZOJ 3822 Domination
    Codeforces Round #271 (Div. 2)
    进程
    线程
    udp和tcp特点 实现文件上传
    面向对象补1
    socket基本语法和粘包
    网络编程
  • 原文地址:https://www.cnblogs.com/chinaniit/p/1523976.html
Copyright © 2011-2022 走看看