When attempting to get a data store reference from a Table or Feature Class object, if that table or feature class has a join specified on it, then the GetDatastore() call fails with an exception. I don't understand why this happens. The Table or Feature Class with the join on it is not the actual Join object because you have to call GetJoin() to get that. So why not continue to treat the original table or feature class as the original dataset object and if you want to check for a join or get a Join object you can, but let the original table or feature class work like normal without these exceptions.
Below is what I have to do to get around this issue (everywhere). The "table" object is a Table class that has a spatial join assigned to it in the map. But to get the data store off that table without an exception I have to do this (see below). My question is why and is there a better way to avoid this? It feels like I'm just having to get the table from itself and that seems foolish.
// Must check this because joined tables are virtual
// and fail when GetDatastore() is called on them.
if (table.IsJoinedTable())
{
// The origin table is the original table
table = table.GetJoin().GetOriginTable();
}