我有一个模仿具有以下结构的数据库表Entity
:CoreData
MySQL
Photo
abv Double
photoId Integer16
photographer String
isActive Boolean
lastUpdated Data
name String
我可以运行以下SQL
语句来获得我想要的结果集:
SELECT `photographerName`, COUNT(`photographerName`)
FROM `Photos`
WHERE `isActive` LIKE 1
GROUP BY `photographerName`
ORDER BY `photographerName`
我可以使用什么组合NSFetchRequest
来获得相同的NSSortDescriptor
结果?NSPredicate
NSExpressionDescription
iOS
我正在使用以下内容:
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Photo"];
NSSortDescriptor *photographerSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"photographer" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
NSPredicate *onlyActivePhotos = [NSPredicate predicateWithFormat:@"isActive == 1"];
request.sortDescriptors = @[photographerSortDescriptor];
request.predicate = onlyActivePhotos;
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
这让我得到isActive
罚款,但为每个返回一行Photo
,而不是Photographer
.
或者......我应该把它分成两部分Entities
吗?例如,与?Photographer
具有一对多关系。Photos