2

I'm trying to use EF in a asp.net vNext SPA application.

I'm registering the context class with the build in dependency injection container using AddScoped() (just like they have it in the examples) but when I try to perform a delete operation on an entity I get weird errors. Sometimes the delete works, sometimes I get a

Invalid operation. The connection is closed.

and sometimes I get a

The connection was not closed. The connection's current state is open.

This only happens for delete operations and I can't find a pattern on when the 'connection is open' and 'connection is closed' appear.

Here's my delete method body (the method is virtual because this is a base controller, though no overrides exist for it yet):

public virtual async Task<IActionResult> Delete(int id)
{
    var t = await Items.SingleOrDefaultAsync(i => i.ID == id);
    if (t == null)
        return new HttpStatusCodeResult((int)HttpStatusCode.NoContent);

    Items.Remove(t);
    AppContext.SaveChanges();

    return new HttpStatusCodeResult((int)HttpStatusCode.OK);
}
4

1 回答 1

0

迁移到 alpha3 后问题消失了

于 2014-09-08T14:31:00.637 回答