• 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();

  • 相关阅读:
    avuex
    vue与avuex
    前端上班第十天
    echarts使用心得
    json转化技巧
    前端上班第一天
    声明函数的提升,声明变量与声明函数之间的区别有什么
    王屋山黑加仑
    微信小程序1
    js-基础
  • 原文地址:https://www.cnblogs.com/chinaniit/p/1523976.html
Copyright © 2020-2023  润新知