This was actually a major oversight on my part. Because my entities were all using native ID generation, they were inserted when they were saved even though I never flushed the transaction. (An exception to the rule. See this excellent explanation: https://stackoverflow.com/a/43567/1015595)
Your Member entity, on the other hand, maps the ID to a Guid. In that case, the objects behave as expected and aren't persisted until the transaction is flushed.
Like Oskar said in his answer, you should begin a transaction before you try to save anything and commit the transaction afterwards. A good practice is to wrap the save in a try-catch statement:
// Adds sample data to our database
public ActionResult Seed()
{
...
StoreRepository.BeginTransaction();
try
{
StoreRepository.SaveOrUpdateAll( barginBasin, superMart );
StoreRepository.Commit();
return RedirectToAction( "Index" );
}
catch
{
StoreRepository.Rollback();
return RedirectToAction( "Error" );
}
}
Here are the methods you'll need to add to your repository:
public void BeginTransaction()
{
Session.BeginTransaction();
}
public void Commit()
{
Session.Transaction.Commit();
}
public void Rollback()
{
Session.Transaction.Rollback();
}
You want to keep these methods in the repository so your controller remains testable.
When I wrote that article, I didn't know anything about NH transactions. The thing that tripped me up was this part of the Castle Windsor documentation:
There's one important, although invisible effect of what we just did.
By registering the components we didn't just tell Windsor how to
create them. Windsor will also take care of properly destroying the
instances for us, thus taking care of managing their full lifetime. In
layman terms, Windsor will dispose both objects when they are no
longer being used. This means it will flush the changes we made to
ISession to the database for us, and it will clean up the
ISessionFactory. And we get all of this for free.
Pretty misleading if you ask me.