I'm experiencing a strange problem when trying to count the entities in a managed object context.
- (NSUInteger)countEntity:(NSString *)entityName 
                inContext:(NSManagedObjectContext *)context{
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:entityName      
                                                  inManagedObjectContext:context];
    [request setEntity:entity];
    [request setIncludesSubentities:NO];
    NSError *error = nil;
    NSUInteger count = [context countForFetchRequest:request error:&error];
    [request release];
    return count;
}
The line:
NSUInteger count = [context countForFetchRequest:request error:&error];
throws a NSInternalInconsistencyException reason: 'entity not found'
Changing to:
NSUInteger count = [[context executeFetchRequest:request error:&error] count];
works without any problem.
I'm at loss here. Any ideas?
Thanks!
/Oskar