CoreData countForFetchRequest says 'entity not found'

core-data, iphone, objective-c

Solution

Running into this today. Started happening when I introduced a second persistent store. Do you have more than one store in the moc? -Ken

Problem

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

Original source