protected List<EntityGroup> BuildEntityGroups(List<object> rawEntities)
{
var jObjects = rawEntities.Select(jt => (dynamic)jt).ToList();
// group the objects by the entityTypeName
var groups = jObjects.GroupBy(jo => (String)jo.entityAspect.entityTypeName).ToList();
// create EntityGroup objects by looking up the entity type and creating the entity instances
var entityInfoGroups = groups.Select(g => {
var entityType = LookupEntityType(g.Key);
var entityInfos = g.Select(jo => CreateEntityInfoFromJson(jo, entityType)).Cast<EntityInfo>().ToList();
return new EntityGroup() { EntityType = entityType, EntityInfos = entityInfos };
}).ToList();
return entityInfoGroups;
}