views:

22

answers:

1

When unit testing with NHibernate I will typically have tests that create and save an object, clear the session (session.Clear()) then retrieve the object from the database.

What's the equivalent of Session.Clear() with EF4?

Example test:

    [Test]
    public void Can_create_and_save_a_default_account()
    {
        var account = new Account();

        _db.Accounts.AddObject(account);
        _db.SaveChanges();

        int id = account.AccountId;

        // clear session

        var fromDb = _db.Accounts.SingleOrDefault(x => x.AccountId == id);
        Assert.IsNotNull(fromDb);
    }
+3  A: 

That will be recreating your DataContext-derived class (_db in your case).

Anton Gogolev