0

我试图运行以下代码:

 [TestMethod]
 [TestCleanup]
 public void TestMethod3()
 {
      using (var context = new CorporateDWTestEntities1())
      {
          //Deleting every row within the OLE_DB_Destination1 table.
          var query = from c in context.SRS_Ticket_Transaction_Stage select c;
          query.Delete();
          context.SaveChanges();
      }
 }

但是,当它运行时,我收到一条错误消息,指出:

“消息:测试方法 Integration_Services_Tests.UnitTest1.TestMethod3 抛出异常:System.Linq.Dynamic.ParseException:'。' 或 '(' 预期测试清理方法 Integration_Services_Tests.UnitTest1.TestMethod3 抛出异常。System.Linq.Dynamic.ParseException: System.Linq.Dynamic.ParseException:'.' 或 ')' 预期。

有谁知道这意味着什么以及如何克服它?

4

1 回答 1

0

根据这个问题,您可能需要将所有记录加载到内存中,然后context.SRS_Ticket_Transaction_Stage.DeleteOnSubmit()为每个项目调用:

[TestMethod]
[TestCleanup]
public void TestMethod3()
{
    using (var context = new CorporateDWTestEntities1())
    {
        //Deleting every row within the OLE_DB_Destination1 table.
        var query = from c in context.SRS_Ticket_Transaction_Stage select c;
        var records = query.ToList();

        foreach(var record in records) 
        {
            context.SRS_Ticket_Transaction_Stage.DeleteOnSubmit(record);
        }
        context.SubmitChanges();
    }
}
于 2013-11-14T21:54:11.383 回答